-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscore2.java
More file actions
107 lines (85 loc) · 2.35 KB
/
score2.java
File metadata and controls
107 lines (85 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import java.util.Scanner;
public class score2{
public static void main(String[] args){
System.out.println("This is a program that allows you to input a set of scores and in turn shows you some relevant data of the scores. ");
//declartion
int n, max,low, s; //numbers of scores in total, highest score, lowest score, score
double mean;
int total=0, pass=0, a=0;
String rank1="",rank2="";
Scanner inp=new Scanner(System.in);
do{
System.out.println("Input the numbers of scores you want to calculate:");
n=inp.nextInt();
int []score=new int[n];
for(int i=0;i<=n-1;i++){
System.out.println("Input the score: ");
s=inp.nextInt();
total=total+s;
score[i]=s;
if(s>60){pass=pass+1;}
if(s>90){a=a+1;}
if(s<=100&&s>=0){
switch((s-50)/10){
case 5:
case 4: rank1="A+";break;
case 3: rank1="A" ;break;
case 2: rank1="B" ;break;
case 1: rank1="C" ;break;
case 0: rank1="D"; break;
default:
rank1="E";break;
}//switchcase
System.out.println("The student's grade is "+rank1+".");
}//if
else
System.out.println("N/A");
}//for loop
int tmp;// using to swap two numbers
for(int i=0;i<=n-2;i++){// selection sort
for(int j=i+1;j<=n-1;j++){
if(score[i]<score[j]){
tmp=score[i];
score[i]=score[j];
score[j]=tmp;
}//if
}//for loop j
}//for loop i
max=score[0];
low=score[n-1];
mean=total/n;
int mean_1=(int)Math.ceil(mean);
switch((mean_1-50)/10){
case 5:
case 4: rank2="A+";break;
case 3: rank2="A" ;break;
case 2: rank2="B" ;break;
case 1: rank2="C" ;break;
case 0: rank2="D"; break;
default:
rank2="E";break;
}//switchcase
for(int i=0;i<=n-1;i++){
System.out.println(score[i]);}
System.out.println(a+","+pass);
System.out.println("Report: ");
System.out.println("Average is "+ mean +".");
System.out.println("\n");
System.out.println("Average is of ABC scale is "+ rank2 +".");
System.out.println("\n");
System.out.println("Highest score is "+ max +".");
System.out.println("\n");
System.out.println("Lowest score is "+low+".");
System.out.println("Rate of people getting A+ is "+ (double)a/n+".");
System.out.println("\n");
System.out.println("Rate of people passing is "+ (double)pass/n+".");
System.out.println("\n");
System.out.print("Do you want to do another calculation? (yes/no): ");
String choice = inp.next();
if (choice.equalsIgnoreCase("no")) {
System.out.println("Program exited.");
break;
}
}while(true);//do while
}//main
}//class