Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

. 1.public static double[] getUserInput() (a) Prompts the user for how many numb

ID: 3759596 • Letter: #

Question

. 1.public static double[] getUserInput()

(a) Prompts the user for how many numbers they will enter, we will cal this size.

(b) Check to make sure that the value of size is 1 or greater.

(c) With the value of size, create a single dimensional array of doubles with the number of elements being the value of size. For example, if size has the value of 4, then your array has 4 elements.

(d) With the created array of doubles, write a loop that reads values in form the keyboard and stores them into the array. If the value of size is 4, you will read in 4 values from the keyboard.(this code is in the slides)

(e) Finally, return the array using the keyword return.

2.public static double arithmeticMean(double[] nums) This method returns the arithmetic mean of the numbers provided by the input parameter, nums.

3. public static double geometricMean(double[] nums) This method returns the geometric mean of the numbers provided by the input parameter, nums.

4.public static double[] minAndmax(double[] nums) This method returns the smallest number and the largest number in the array provided by the input parameter. You dont need to return the location of the min and max.

5.public static double[] scaleUp(double[] nums, double fac- tor) This method multiplies every number provided by the first input parameter with a scaling factor (the second parameter). Make sure that the factor is a 1 2. 3. 4. 5. value greater than or equal to 1.0. If the factor is less than one, just return from the method.

6. public static double[] scaleDown(double[] nums, double factor) This method divides every number provided by the first input parameter with a scaling factor (the second parameter). Make sure that the factor is a value greater than or equal to 1.0. If the factor is less than one, just return from the method.

7. Main method: In this method, 1. obtain the numbers from the user using the method getUserInput() de- scribed above. 2. provide the user with 6 possible choices, each corresponding to one of the methods above and a exit option. Exclude getUserInput as an option. Option 1 - arithmeticMean Option 2 - geometricMean Option 3 - minAndmax Option 4 - scaleUp Option 5 - scaleDown Option 6 - Exit

HINT: A switch statement would be the easiest structure to use for this menu. 3. prompt the user to pick one. Check the user input for its validity, it has to be a number between 1 and 6. a. If option 4 (Scale up) or 5 (Scale down) is selected by the user then prompt the user for a value for factor. 4. perform the requested operation, and output the corresponding statis- tic(s). If Exit option was selected then terminate the program. 5. loop back to step 2. Note that this program should only use 1 array for the entire program. DO NOT CREATE a new array for each method.

Explanation / Answer

implemented parts of the question - 1,2,3 and 7


import java.util.Scanner;

public class ArthematicOperTest {
  
   static Scanner scan = new Scanner(System.in);
   public static void main(String[] args) {
       double nums[] = ArthematicOperTest.getUserInput();
       if(nums != null) {
           System.out.println("Menu: " +
                   " Option 1 - arithmeticMean " +
                   " Option 2 - geometricMean " +
                   " Option 3 - minAndmax " +
                   " Option 4 - scaleUp " +
                   " Option 5 - scaleDown " +
                   " Option 6 - Exit");
          
           int option = 0;
           while(option != 6) {
              
               option = scan.nextInt();
               switch(option) {
                   case 1:
                       System.out.println("Arthematic Mean: "+ ArthematicOperTest.arithmeticMean(nums));
                       break;
                  
                   case 2:
                       System.out.println("Geomatric Mean: "+ ArthematicOperTest.geometricMean(nums));
                       break;
                   case 6:
                       break;
                      
                   case 3:
                       //implement other functions
                       break;
                   case 4:
                       //implement other functions
                       break;
                   case 5:
                       //implement other functions
                       break;
                   default:
                       System.out.println("Enter valid option");
                       break;
               }
           }
          
       }
   }
  
  
   public static double[] getUserInput() {
       System.out.println("Hom many numbers you want to enter?");
       int size = scan.nextInt();
       if(size > 0) {
           //read the numbers
           double nums[] = new double[size];
           for(int i = 0; i < size; i++) {
               System.out.println("Enter number #"+(i+1)+": ");
               nums[i] = scan.nextDouble();
           }
           return nums;
          
       }
       return null;
   }
  
   public static double arithmeticMean(double[] nums) {
       double total = 0;
       int size = nums.length;
       if(size > 0) {
           for(int i = 0; i < size; i++) {
               total += nums[i];
           }
           return total/size;
       }
       return 0;
   }
  
   public static double geometricMean(double[] nums) {
       double product = 1;
       int size = nums.length;
       if(size > 0) {
           for(int i = 0; i < size; i++) {
               product *= nums[i];
           }
      
           return Math.pow(10, Math.log10(product)/size);
       }
       return 0;
   }
}
--output------------------

Hom many numbers you want to enter?
4
Enter number #1:
1
Enter number #2:
2
Enter number #3:
4
Enter number #4:
8
Menu:
Option 1 - arithmeticMean
Option 2 - geometricMean
Option 3 - minAndmax
Option 4 - scaleUp
Option 5 - scaleDown
Option 6 - Exit
1
Arthematic Mean: 3.75
2
Geomatric Mean: 2.82842712474619
6