Advertisement
Guest User

Untitled

a guest
Oct 24th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. public class Prog02
  4. {
  5. public static void main(String[] args) throws IOException {
  6. //Declare variables
  7. final double MIN = 10, MAX = 1000;
  8. double range, calcMin = 102, calcMax = -2, calcMean = 0.0, fileInput = 0.0, sum = 0.0;
  9. int mean = 0;
  10. double stdev;
  11. char choice;
  12. String userInput;
  13. int n, randNums = 0;
  14.  
  15. Scanner kb = new Scanner(System.in);
  16. Random rgen = new Random();
  17.  
  18. System.out.println("Prog02 will generate n normally distributed values.");
  19. System.out.println("User will give n (10 <= n <= 1000), the target mean and standard deviation.");
  20. System.out.println("Prog02 will then:");
  21. System.out.println("\t1 - Generate the n numbers");
  22. System.out.println("\t2 - Draw a bar chart");
  23. System.out.println("\t3 - Calculate and display min, max, range, mean, and standard deviation");
  24. System.out.println("\t4 - Ask if you want to repeat the process");
  25.  
  26. do {
  27. System.out.print("How many random numbers do you want (10..1000): ");
  28. n = kb.nextInt();
  29. while ( n < MIN || n > MAX) {
  30. System.out.println("ERROR: Number must be between 10 and 1000 inclusive.");
  31. System.out.print("How many random numbers do you want (10..1000): ");
  32. n = kb.nextInt();
  33. }
  34. System.out.print("What mean do you want: ");
  35. mean = kb.nextInt();
  36. System.out.print("What standard deviation: ");
  37. stdev = kb.nextInt();
  38.  
  39. System.out.println("Bar Chart for the normally distributed integers in file");
  40. for (int i = 0; i <= n; i++) {
  41. randNums = (int)(rgen.nextGaussian() * stdev + mean);
  42. System.out.println(randNums + ":");
  43. if (calcMax < randNums)
  44. calcMax = randNums;
  45. if (calcMin < randNums)
  46. calcMin = randNums;
  47. }
  48. range = (calcMax - calcMin) + 1;
  49. sum = sum + randNums;
  50. System.out.printf("\nMeasures for the uniformly distributed integers in file, Nums" + n + ".txt");
  51. System.out.printf("\nMin: %.2f", calcMin);
  52. System.out.printf("\nMax: %.2f", calcMax);
  53. System.out.printf("\nRange: %.2f", range);
  54. System.out.print("\nWant to generate another list of numbers? (y or n) ");
  55. userInput = kb.next();
  56. choice = userInput.charAt(0);
  57. }
  58. while (Character.toUpperCase(choice) == 'Y');
  59. if (Character.toUpperCase(choice) != 'Y');
  60. System.out.println("Prog02 terminating . . .");
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement