Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Prog02
- {
- public static void main(String[] args) throws IOException {
- //Declare variables
- final double MIN = 10, MAX = 1000;
- double range, calcMin = 102, calcMax = -2, calcMean = 0.0, fileInput = 0.0, sum = 0.0;
- int mean = 0;
- double stdev;
- char choice;
- String userInput;
- int n, randNums = 0;
- Scanner kb = new Scanner(System.in);
- Random rgen = new Random();
- System.out.println("Prog02 will generate n normally distributed values.");
- System.out.println("User will give n (10 <= n <= 1000), the target mean and standard deviation.");
- System.out.println("Prog02 will then:");
- System.out.println("\t1 - Generate the n numbers");
- System.out.println("\t2 - Draw a bar chart");
- System.out.println("\t3 - Calculate and display min, max, range, mean, and standard deviation");
- System.out.println("\t4 - Ask if you want to repeat the process");
- do {
- System.out.print("How many random numbers do you want (10..1000): ");
- n = kb.nextInt();
- while ( n < MIN || n > MAX) {
- System.out.println("ERROR: Number must be between 10 and 1000 inclusive.");
- System.out.print("How many random numbers do you want (10..1000): ");
- n = kb.nextInt();
- }
- System.out.print("What mean do you want: ");
- mean = kb.nextInt();
- System.out.print("What standard deviation: ");
- stdev = kb.nextInt();
- System.out.println("Bar Chart for the normally distributed integers in file");
- for (int i = 0; i <= n; i++) {
- randNums = (int)(rgen.nextGaussian() * stdev + mean);
- System.out.println(randNums + ":");
- if (calcMax < randNums)
- calcMax = randNums;
- if (calcMin < randNums)
- calcMin = randNums;
- }
- range = (calcMax - calcMin) + 1;
- sum = sum + randNums;
- System.out.printf("\nMeasures for the uniformly distributed integers in file, Nums" + n + ".txt");
- System.out.printf("\nMin: %.2f", calcMin);
- System.out.printf("\nMax: %.2f", calcMax);
- System.out.printf("\nRange: %.2f", range);
- System.out.print("\nWant to generate another list of numbers? (y or n) ");
- userInput = kb.next();
- choice = userInput.charAt(0);
- }
- while (Character.toUpperCase(choice) == 'Y');
- if (Character.toUpperCase(choice) != 'Y');
- System.out.println("Prog02 terminating . . .");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement