Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

input ={87,64,94,100,83,78,85,91,76,87} //not from user output = grade distribution: 00-09 10-19 20-29 30-39 40-49 50-59 60-69 * 70-79 ** 80-89 **** 90-99 ** 100 *

input ={87,64,94,100,83,78,85,91,76,87} //not from user

output = grade distribution:

00-09

10-19

20-29

30-39

40-49

50-59

60-69 *

70-79 **

80-89 ****

90-99 **

100 *

the following is my code. What am I doing wrong with my switch case?

class Main {

/* create a program that will allow a profesor to see his students

grade distribution from the last test.

steps:

1. take in all the grades or make an array that places the value of how many students hit a grade in that index grouping meaning index 1 = 100 if index 1 value equal 3 than 3 students got 100 if there are grades in index 2 then they group together grades between 20 -29 and so on

2. tally when a grade falls into a grouping

3. group all the grades to allow groups to represent letter grades (assuming that there are no - or + )therfore 100 = 100 90-99 = A 80 - 89 = B and so on...

therfore 0,1,2,3,4,5,6,7,8,9 can represent each letter grade if multiplied by ten

*/

public static void main(String[] args) {

int [] arr ={87,64,94,100,83,78,85,91,76,87};

int [] newArr = new int [10];

for(int i = 0; i < arr.length ; i++){

//int gradeGroup = 0;

//System.out.println("grade group"+gradeGroup);

if(i == 10)

{

System.out.printf("%5d%n", 100);

}else{

System.out.printf("%d-%d%n", i * 10, i * 10 + 9);

}

for(int j = 0; j < arr.length; j++){

switch(arr[j] / 10){

case 0 : System.out.printf("*");//int a = a += 1; newArr[0] = a;

break;

case 1 :System.out.printf("*");//int b = b += 1; newArr[1] = b;

break;

case 2 :System.out.printf("*");//int c = c += 1; newArr[2] = c;

break;

case 3 :System.out.printf("* %n");//int d = d += 1; newArr[3] = d;

break;

case 4 :System.out.printf("*%n");//int e = e += 1; newArr[4] = e;

break;

case 5 :System.out.printf("*%n");//int f = f += 1; newArr[5] = f;

break;

case 6 :System.out.printf("*%n");//int g = g += 1; newArr[6] = g;

break;

case 7 :System.out.printf("*%n");//int h = h += 1; newArr[7] = h;

break;

case 8 :System.out.printf("*%n");//int k = k += 1; newArr[8] = k;

break;

case 9 :System.out.printf("*%n");//int l = l += 1; newArr[9] = l;

break;

case 10 :System.out.printf("*%n");//int m= m += 1; newArr[10] = m;

break;

default : System.out.println("wrong");

}

}

}

}

/*int[] c = new int[10];

System.out.printf("%s%10s%n", "index", "value");

System.out.println("_____________________");

for(int counter = 0; counter < c.length; counter++){

System.out.printf("%2d%12d%n", counter, c[counter]);

if (counter >= (c.length -1)){}

else{

System.out.println("_____________________");

}

}*/

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions