Advertisement
SourCB

ch20ex1: Not Done

Mar 25th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.34 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class ch20ex1 {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.  
  9.  
  10.  
  11.  
  12.         double x, wut = 0, c;
  13.  
  14.         double sum = 0, avg = 0, min = 0, max = 0, sd = 0, mode = 0;
  15.         double med = 0;
  16.  
  17.  
  18.  
  19.         System.out.println("Enter the number of grades: ");
  20.         x = scan.nextDouble();
  21.  
  22.  
  23.  
  24.  
  25.  
  26.         double[] grades = new double[x];
  27.  
  28.  
  29.         for (int index = 0; index < x; index++) {
  30.             wut = index + 1;
  31.             System.out.println("Enter the grade for student " + wut + ": ");
  32.             grades[index] = scan.nextInt();
  33.  
  34.  
  35.         }
  36.  
  37.         System.out.println("What would you like to find? ");
  38.         System.out.println("[1]= average");
  39.         System.out.println("[2]= minimum");
  40.         System.out.println("[3]= maximum");
  41.         System.out.println("[4]= standard deviation");
  42.         System.out.println("[5]= median");
  43.         System.out.println("[6]= mode");
  44.         System.out.println("[7]= exit");
  45.         c = scan.nextInt();
  46.  
  47.  
  48.         // Calculating the sum
  49.         for (int index = 0; index < x; index++) {
  50.             sum = sum + grades[index];
  51.         }
  52.  
  53.  
  54.  
  55.         // Calculating avg
  56.         if (c == 1) {
  57.             avg = sum / x;
  58.             System.out.println("Average: " + avg);      //   ***DELETE "for" LOOPS BELOW***
  59.         }
  60.  
  61.  
  62.  
  63.  
  64.         //Calculating min
  65.         if (c == 2) {
  66.             min = grades[0];
  67.             for (int index = 0; index < grades.length; index++) {
  68.                 if (grades[index] < min) {
  69.                     min = grades[index];
  70.                    
  71.                 }
  72.             }
  73.             System.out.println("Min: " + min);
  74.         }
  75.        
  76.  
  77.  
  78.         //Calculating max
  79.         if (c == 3) {
  80.             max = grades[0];
  81.             for (int index = 0; index < grades.length; index++) {
  82.                 if (grades[index] > max) {
  83.                     max = grades[index];
  84.                    
  85.                 }
  86.             }
  87.             System.out.println("Max: " + max);
  88.  
  89.         }
  90.        
  91.  
  92.  
  93.         //Calculating sd
  94.         for (int index = 0; index < x; index++) {       //Skipping sd for now
  95.             if (c == 4) {
  96.             }
  97.         }
  98.  
  99.         //Calculating med
  100.               //
  101.             if (c == 5) {
  102.                 double o = 0, L = 0, k = 0, g = 0;
  103.                 for( int index = 0; index < grades.length; index++ ){
  104.                     if( grades.length % 2 != 0){
  105.                         L = grades.length - 1;
  106.                         o = L / 2;
  107.                         k = o + 1;
  108.                         med = grades[o];
  109.  
  110.                     }
  111.                     if( grades.length % 2 == 0 ){
  112.                         L = grades.length / 2;
  113.                         o = L + 1;
  114.                         k = grades[L] + grades[o];
  115.                         g = k / 2;
  116.                         med = g;
  117.  
  118.  
  119.                     }
  120.                 }
  121.                 System.out.println("Median: " + med);
  122.             }
  123.        
  124.  
  125.         //Calculating mode
  126.         for (int index = 0; index < x; index++) {       //
  127.             if (c == 6) {
  128.             }
  129.         }
  130.  
  131.         //Calculating exit thing
  132.         if (c == 7) {
  133.             System.out.println("Goodbye o/");
  134.             System.exit(0);
  135.         }
  136.  
  137.  
  138.  
  139.  
  140.  
  141.     }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement