Question

In: Computer Science

Create a program in java with the following information: Design a program that uses an array...

Create a program in java with the following information:

Design a program that uses an array with specified values to display the following:

The lowest number in the array

The highest number in the array

The total of the numbers in the array

The average of the numbers in the array

Initialize an array with these specific 20 numbers: 26 45 56 12 78 74 39 22 5 90 87 32 28 11 93 62 79 53 22 51

example output:

The array was initialized to:
26 45 56 12 78 74 39 22 5 90 87 32 28 11 93 62 79 53 22 51
The lowest number is: 5
The highest number is: 93
The total of the numbers is: 965

Please use the code below to design the program above:

// Chapter 6 Figure 6-15
// psuedocode embedded as comments
// Ray Warren
// 5 June 2020 - create C++
// 17 Aug 2020 C++ -> java

import java.util.Scanner;

public class DiscountRate
{
// CONSTANTS
// Create a Scanner object for keyboard input.
static final Scanner KEYBOARD = new Scanner(System.in);   

// start
public static void main(String[] args)
{
// Declaration
// num quantity
int quantity;
// num SIZE = 4, local CONSTANT
final int SIZE = 4;
// num DISCOUNTS[4] = 0, 0.10, 0.15, 0.20
double DISCOUNTS[] = {0, 0.10, 0.15, 0.20};
// num QUAN_LIMITS[4] = 0, 9, 13, 26
int QUAN_LIMITS[] = {0, 9, 13, 26};
// num x
// int x; // NOT USED
// num QUIT = -1
int QUIT = -1;
// housekeeping()
quantity = housekeeping(QUIT);
// while quantity <> QUIT
while (quantity != QUIT){
// determineDiscount()
quantity = determineDiscount(SIZE, QUIT, quantity, QUAN_LIMITS, DISCOUNTS);
// endwhile
} // end while
// finish()
finish();

} // end main()
// stop

// housekeeping()
public static int housekeeping(int QUIT) {
// output "Entry quantity ordered or ", QUIT, " to quit "
System.out.println("Entry quantity ordered or " + QUIT + " to quit ");
// input quantity
int quantity = KEYBOARD.nextInt();
// return
return quantity;
} // end housekeeping()

// determineDiscount()
public static int determineDiscount(int SIZE, int QUIT, int quantity, int QUAN_LIMITS[], double DISCOUNTS[] ) {
// x = SIZE - 1
int x = (SIZE - 1);
// while quantity < QUAN_LIMIT[x]
while (quantity < QUAN_LIMITS[x]) {
// x = x-1
x = x-1;
// endwhile
} // end while
// output "Your discount rate is ", DISCOUNTS[x]
System.out.println("Your discount rate is " + DISCOUNTS[x]);
// output "Enter quantity ordered or ", QUIT, " to quit "
System.out.println("Enter quantity ordered or " + QUIT + " to quit ");
// input quantity
quantity = KEYBOARD.nextInt();;
// return
return quantity;
} // end determineDiscount()

// finish()
public static void finish() {
// output "End of job"
System.out.println("End of job");
// return
} // end finish()

} // end class


Solutions

Expert Solution

Java program to find the minum, maximum,sum of the elements in an Array

----------------------------------------------------------

import java.io.*;
  
public class Tofind_max_min_sum {
  
static int minValue(int array[], int n) //Method to find the Minimum element in array
{
int item = array[0];
  
for (int j = 1; j < n; j++)
item = Math.min(item, array[j]);
return item;
}
static int sumValue(int array[],int n) //Method to find the sum of elements in an array
{
int item = 0;
for(int j = 0; j < n;j++)
item = item+array[j];
return item;
}
static int maxValue(int array[], int n) //Method to find the Maximum element in array
{
int item = array[0];
  
for (int j = 1; j < n; j++)
item = Math.max(item, array[j]);
return item;
}


// Driver code
public static void main (String[] args)
{
int array[] = {26,45,56,12,78,74,39,22,5,90,87,32,28,11,93,62,79,53,22,51 };
int n = array.length;
System.out.println( "The Lowest Number is: "
+ minValue(array, n)); //Print the mimimum element in the array
System.out.println( "The highest Number is: "
+ maxValue(array, n)); //print the maximum element in the array
System.out.println( "The total of the number is: "
+sumValue(array, n)); ////Print the sum of elements in the Array
}
}
------------------------------------------

-----------------------------------------------------------------

Kindly Comment your queries if any,upvote if you like it.Thank You!!


Related Solutions

Write a program in Java to do the following: -Create a one-dimensional array of 7 integers...
Write a program in Java to do the following: -Create a one-dimensional array of 7 integers as follows: Assign {35,20,-43,-10,6,7,13} -Create a one dimensional array of 7 Boolean values as follows: Assign {true,false,false,true,false,true,false} -Create a one dimensional array of 7 floating-point values as follows: Assign {12.0f,1.5f,-3.5f,-2.54f,3.4f,45.34f,22.13f} -Declare sum as integer and set it to 0. -Declare sumf as float and set it to 0.0f. -Use a for loop to go through each element of the Boolean array, and if an...
Java program In the main(), create and load a 2-dimentional array to hold the following sales...
Java program In the main(), create and load a 2-dimentional array to hold the following sales data Number of Tacos Sold (hard code the data into the array when you create it) Truck3 Truck4 .    Truck5 Monday 250 334 229 Wednesday   390 145 298 Friday .    434 285 . 156 • Write a method to calculate the grand total of all Tacos sold Write a method to allow the user to enter a truck number and get the total...
Write a Java program to create an array of a specific size (which is an input...
Write a Java program to create an array of a specific size (which is an input from the user) and fill it with random numbers between 1 and 100. Then sort the array and count how many of these numbers are originally at sorted position. Display that original array, the sorted array, and the count (number of elements originally at sorted position).
CSC MUST BE IN JAVA Design a program as per the following information using the accompanying...
CSC MUST BE IN JAVA Design a program as per the following information using the accompanying data file. Here is the datafile: sodaSalesB.dat Make sure the program compiles and that you include pseudo code. The assignment is worth 100 points.  (Lack of pseudo code will cost you 15pts) You have been asked to produce the report below. This report will tell the company how sales are going. You will read the file named sodasales.dat The values are the brand name, number...
Using JAVA Write a program that uses a 2-D array to store the highest and lowest...
Using JAVA Write a program that uses a 2-D array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and highest and lowest temperatures of the year. Your program must consist of the following methods with their appropriate parameters: a.) getData: This method reads and stores the data in the 2-D array. b.) averageHigh: This method calculates and returns the average high temperature of the year. c.)...
Using C++ language, create a program that uses a struct with array variables that will loop...
Using C++ language, create a program that uses a struct with array variables that will loop at least 3 times and get the below information: First Name Last Name Job Title Employee Number Hours Worked Hourly Wage Number of Deductions Claimed Then, determine if the person is entitled to overtime and gross pay. Afterwards, determine the tax and net pay. Output everything to the screen. Use functions wherever possible. Bonus Points: Use an input file to read in an unknown...
Create a program in java using the following information: Trainers at Tom's Athletic Club are encouraged...
Create a program in java using the following information: Trainers at Tom's Athletic Club are encouraged to enroll new members. Write an application that extracts the names of Trainers and groups them based on the number of new members each trainer has enrolled this year. Output is the number of trainers who have enrolled 0 to 5 members, 6 to 12 members, 13 to 20 members, and more than 20 members. Give their names as well as the number of...
Write a java program using the following information Design a LandTract class that has two fields...
Write a java program using the following information Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a double), and one for the width (a double). The class should have:  a constructor that accepts arguments for the two fields  a method that returns the tract’s area(i.e. length * width)  an equals method that accepts a LandTract object as an argument. If the argument object holds the same data (i.e. length and...
Answer the following in Java programming language Create a Java Program that will import a file...
Answer the following in Java programming language Create a Java Program that will import a file of contacts (contacts.txt) into a database (Just their first name and 10-digit phone number). The database should use the following class to represent each entry: public class contact {    String firstName;    String phoneNum; } Furthermore, your program should have two classes. (1) DatabaseDirectory.java:    This class should declare ArrayList as a private datafield to store objects into the database (theDatabase) with the...
Write a Java program that reads a list of integers into an array. The program should...
Write a Java program that reads a list of integers into an array. The program should read this array from the file “input.txt”. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is a two-column list. The first column is the list of the distinct array elements; the second column is the number of occurrences of each element. The list should be sorted on entries in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT