/home/caleb/ASDV-Java/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/Stats.java |
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
package mp3_calebfontenot;
import java.util.Scanner;
@author
public class Stats {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
double mean = 0;
double inputSum = 0, numberOfTimesRun = 0, inputPow = 0, deviation = 0;
String userInput = "";
do {
System.out.println("Press Y/y to enter a series of numbers or Q/q to quit.");
System.out.println("Current sum: " + inputSum);
userInput = input.next();
if (userInput.toLowerCase().equals("y")) {
try {
do {
System.out.print("Please enter a series of numbers; Type '-1' to quit (no quotes, you doofus!): ");
userInput = input.next();
if (Double.parseDouble(userInput) != -1) {
inputSum += Double.parseDouble(userInput);
inputPow += Math.pow(Double.parseDouble(userInput), 2);
numberOfTimesRun++;
}
if (numberOfTimesRun == 0) {
System.out.println("No numbers entered!");
}
System.out.println("Current sum: " + inputSum);
System.out.println("Input sum^2: " + inputPow);
} while (Double.parseDouble(userInput) != -1);
} catch (Exception e) {
System.out.println("Invalid input!");
}
} else {
System.out.println("Invalid input!");
}
mean = inputSum / numberOfTimesRun;
if (numberOfTimesRun == 1) {
deviation = 0;
} else {
deviation = Math.sqrt((inputPow - (Math.pow(inputSum, 2) / numberOfTimesRun)) / (numberOfTimesRun - 1));
}
System.out.println();
System.out.println("The mean is: " + mean);
System.out.println("The deviation is: " + deviation);
}
while (!(userInput.toLowerCase().equals("q")));
}
}