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

/* * To change this license header, choose License Headers in Project Properties

ID: 3760563 • Letter: #

Question

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package simplestatistic;

import java.util.Scanner;
import java.util.Arrays;

/**
*
* @author Alvaro
*/
public class SimpleStatistic {

/**
* @param args the command line arguments
*/
public static double[] getUserInput() {
Scanner read_from_keyboard = new Scanner(System.in);
int size;
System.out.print("Enter how many numbers you want: ");
size = read_from_keyboard.nextInt();
if (size >= 1) {
System.out.println("The number you entered is less than one.");
} else {
System.out.println("The number you entered is greater than or equal to one.");
}
double[] nums = new double[size];
System.out.println("Enter " + nums.length + " Values: ");

for (int i = 0; i < nums.length; i++) {
nums[i] = read_from_keyboard.nextDouble();
}
System.out.println("Your number are " + Arrays.toString(nums));
System.out.println();
return nums;
}

public static double arithmeticMean(double[] nums) {
double total = 0;
int size = nums.length;
if (size > 1) {
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 > 1) {
for (int i = 0; i < size; i++) {
product *= nums[i];
}
}
return 0;
}

public static double[] minAndmax(double[] nums) {
double minimun_max = 0;
int size = nums.length;
if (size > 1) {
for (int i = 0; i < size; i++) {
minimun_max += nums[i];

}

}
return null;
}

public static double[] scaleUp(double[] nums, double factor) {
Scanner read_from_keyboard = new Scanner(System.in);
int scaleUp = read_from_keyboard.nextInt();
int size = nums.length;
if (size > 1) {
for (int i = 0; i < size; i++) {
nums[i] *= scaleUp;
}
}

return null;

}

public static double[] scaleDown(double[] nums, double factor) {
Scanner read_from_keyboard = new Scanner(System.in);
int scaleDown = read_from_keyboard.nextInt();
int size = nums.length;
if (size > 1) {
for (int i = 0; i < size; i++) {
nums[i] /= scaleDown;
}
}
return null;

}

public static void main(String[] args) {
double[] newarr = getUserInput();
System.out.println("The 6 ptions are: ");
System.out.println("Option 1 - arithmeticMean ");
System.out.println("Option 2 - geometricMean ");
System.out.println("Option 3 - minAndmax ");
System.out.println("OPtion 4 - scaleUp ");
System.out.println("Option 5 - scaleDown ");
System.out.println("OPtion 6 - Exit ");
System.out.println();
Scanner option = new Scanner(System.in);
int options;
System.out.println("Enter the Option number you want to Enter: ");
options = option.nextInt();
System.out.println("You chose Option:" + options);

switch (options) {
case 1:
arithmeticMean(newarr);
break;
case 2:
geometricMean(newarr);
break;
case 3:
minAndmax(newarr);
break;
case 4:
scaleUp(newarr, 0);
break;
case 5:
scaleDown(newarr, 0);
break;
default:
System.out.println("Enter valid option");
break;

}
}
}

Can you check if is correct?

Explanation / Answer

The Program is fine has no compile time errors. However you should be carefull while compiling and running the program as this program uses package. Here are the steps to compile and run the program

To compile:    javac -d . SimpleStatistic.java

To run:   java simplestatistic.SimpleStatistic