In: Computer Science
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
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!!