Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ch20ex1 {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- double x, wut = 0, c;
- double sum = 0, avg = 0, min = 0, max = 0, sd = 0, mode = 0;
- double med = 0;
- System.out.println("Enter the number of grades: ");
- x = scan.nextDouble();
- double[] grades = new double[x];
- for (int index = 0; index < x; index++) {
- wut = index + 1;
- System.out.println("Enter the grade for student " + wut + ": ");
- grades[index] = scan.nextInt();
- }
- System.out.println("What would you like to find? ");
- System.out.println("[1]= average");
- System.out.println("[2]= minimum");
- System.out.println("[3]= maximum");
- System.out.println("[4]= standard deviation");
- System.out.println("[5]= median");
- System.out.println("[6]= mode");
- System.out.println("[7]= exit");
- c = scan.nextInt();
- // Calculating the sum
- for (int index = 0; index < x; index++) {
- sum = sum + grades[index];
- }
- // Calculating avg
- if (c == 1) {
- avg = sum / x;
- System.out.println("Average: " + avg); // ***DELETE "for" LOOPS BELOW***
- }
- //Calculating min
- if (c == 2) {
- min = grades[0];
- for (int index = 0; index < grades.length; index++) {
- if (grades[index] < min) {
- min = grades[index];
- }
- }
- System.out.println("Min: " + min);
- }
- //Calculating max
- if (c == 3) {
- max = grades[0];
- for (int index = 0; index < grades.length; index++) {
- if (grades[index] > max) {
- max = grades[index];
- }
- }
- System.out.println("Max: " + max);
- }
- //Calculating sd
- for (int index = 0; index < x; index++) { //Skipping sd for now
- if (c == 4) {
- }
- }
- //Calculating med
- //
- if (c == 5) {
- double o = 0, L = 0, k = 0, g = 0;
- for( int index = 0; index < grades.length; index++ ){
- if( grades.length % 2 != 0){
- L = grades.length - 1;
- o = L / 2;
- k = o + 1;
- med = grades[o];
- }
- if( grades.length % 2 == 0 ){
- L = grades.length / 2;
- o = L + 1;
- k = grades[L] + grades[o];
- g = k / 2;
- med = g;
- }
- }
- System.out.println("Median: " + med);
- }
- //Calculating mode
- for (int index = 0; index < x; index++) { //
- if (c == 6) {
- }
- }
- //Calculating exit thing
- if (c == 7) {
- System.out.println("Goodbye o/");
- System.exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement