-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestStudentGrade.java
More file actions
87 lines (71 loc) · 2.27 KB
/
Copy pathTestStudentGrade.java
File metadata and controls
87 lines (71 loc) · 2.27 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
// Brooklynn Silva
// Final Program
// TEST Student Grade Class
// July 31, 2020
import java.util.InputMismatchException;
import java.util.Scanner;
public class TestStudentGrade {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// declared variables
int assignment1 = 0;
int assignment2 = 0;
int assignment3 = 0;
int test1 = 0;
int test2 = 0;
int participationScore = 0;
// try/catch block for exception handling (InputMismatchException)
try {
System.out.println("Enter the score for Assignment 1:");
assignment1 = input.nextInt();
}
catch (InputMismatchException grades) {
System.out.println("Try again with a valid numerical value.");
System.exit(0);
}
try {
System.out.println("Enter the score for Assignment 2:");
assignment2 = input.nextInt();
}
catch (InputMismatchException grades) {
System.out.println("Try again with a valid numerical value.");
System.exit(0);
}
try {
System.out.println("Enter the score for Assignment 3:");
assignment3 = input.nextInt();
}
catch (InputMismatchException grades) {
System.out.println("Try again with a valid numerical value.");
System.exit(0);
}
try {
System.out.println("Enter the score for Test 1:");
test1 = input.nextInt();
}
catch (InputMismatchException grades) {
System.out.println("Try again with a valid numerical value.");
System.exit(0);
}
try {
System.out.println("Enter the score for Test 2:");
test2 = input.nextInt();
}
catch (InputMismatchException grades) {
System.out.println("Try again with a valid numerical value.");
System.exit(0);
}
try {
System.out.println("Enter the score for Participation:");
participationScore = input.nextInt();
}
catch (InputMismatchException grades) {
System.out.println("Try again with a valid numerical value.");
System.exit(0);
}
// run established scores through the Student Grade Class and calculate the final score and grade for the output
StudentGrade studentGrade = new StudentGrade(assignment1, assignment2, assignment3, test1, test2, participationScore);
System.out.printf("Final Score: %.2f\n", studentGrade.calculateScore());
System.out.println("Final Grade: " + studentGrade.calculateGrade());
}
}