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

Java the goal is to create a list class that uses an array to implement the...
Java the goal is to create a list class that uses an array to implement the interface below. I'm having trouble figuring out the remove(T element) and set(int index, T element). I haven't added any custom methods other than a simple expand method that doubles the size by 2. I would prefer it if you did not use any other custom methods. Please use Java Generics, Thank you. import java.util.*; /** * Interface for an Iterable, Indexed, Unsorted List ADT....
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).
In C++ using a single dimensional array Create a program that uses a for loop to...
In C++ using a single dimensional array Create a program that uses a for loop to input the day, the high temperature, and low temperature for each day of the week. The day, high, and low will be placed into three elements of the array. For each loop the day, high, and low will be placed into the next set of elements of the array. After the days and temps for all seven days have been entered into the array,...
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...
IN JAVA Create a program that uses a nested for loop to display a rectangle of...
IN JAVA Create a program that uses a nested for loop to display a rectangle of #'s with a given number of rows and columns,. This should only display the # when the column is an odd number (see examples below). Get the number of rows and columns from the user, and display the result. Examples: If the user provided rows=4, and columns=7, the program should display a pattern as follows: # # # # # # # # #...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Prompt the user for 12 months of highest and lowest.   Write two methods : one to calculate and return the average high and one to calculate and return the average low of the year. Your program should output all the values in the array and then output the average high and the average low. im trying to...
Create a program in JAVA that displays a design or picture for someone in your quarantine...
Create a program in JAVA that displays a design or picture for someone in your quarantine household/group: a pet, a parent, a sibling, a friend. Make them a picture using the tools in TurtleGraphics and run your program to share it with them! Use a pen object, as well as any of the shape class objects to help you create your design. You must use and draw at least 5 shape objects. - You must use a minimum of 4...
3) Create a Java program that uses NO methods, but use scanner: Write a program where...
3) Create a Java program that uses NO methods, but use scanner: Write a program where you will enter the flying distance from one continent to another, you will take the plane in one country, then you will enter miles per gallon and price of gallon and in the end it will calculate how much gas was spend for that distance in miles. Steps: 1) Prompt user to enter the name of country that you are 2) Declare variable to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT