-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGradeBook.java
More file actions
93 lines (81 loc) · 2.07 KB
/
Copy pathGradeBook.java
File metadata and controls
93 lines (81 loc) · 2.07 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
import java.util.Scanner;
public class GradeBook {
private String courseName;
private int courseCode;
private int counter;
private int total;
private int aCount;
private int bCount;
private int cCount;
private int dCount;
private int eCount;
private int fCount;
public void setCourseName(String nameOfCourse) {
courseName = nameOfCourse;
}
public void setCourseCode(int codeOfCourse) {
courseCode = codeOfCourse;
}
public String getCourseName() {
return courseName;
}
public int getCourseCode() {
return courseCode;
}
public void displayGradeReport() {
System.out.println("Grade Report");
if (counter != 0) {
double average = (double) total / counter;
System.out.printf("Total of the %d Grades Entered is: %d\n", counter, total);
System.out.printf("The Average is:%.2f%n", average);
System.out.printf("%s\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d",
"Number of Students Who received each grades: ",
"A: ", aCount,
"B: ", bCount,
"C: ", cCount,
"D: ", dCount,
"E: ", eCount,
"F: ", fCount);
} else {
System.out.println("No Grades were Entered");
}
}
public void inputGrades() {
Scanner input = new Scanner(System.in);
int grade;
System.out.printf("%s\n%s\n %s\n %s\n",
"Enter Grade From Range of 0-100",
"Type End of File indicator to terminate input: ",
"On UNIX/Linux/Mac OS X type <Ctrl> d then press Enter",
"On Windows type <Ctrl> z then press Enter");
while (input.hasNext()) {
grade = input.nextInt();
total += grade;
counter++;
incrementLetterGradeCounter(grade);
}
}
private void incrementLetterGradeCounter(int grade) {
switch (grade / 10) {
case 9:
case 10:
aCount++;
break;
case 8:
bCount++;
break;
case 7:
cCount++;
break;
case 6:
dCount++;
break;
case 5:
eCount++;
break;
default:
fCount++;
break;
}
}
}