File tree Expand file tree Collapse file tree 3 files changed +94
-18
lines changed
Programming-Challenges/Decision-Structures
out/production/Decision-Structures/com/challenges Expand file tree Collapse file tree 3 files changed +94
-18
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Write a program that has variables to hold three test scores.
3
+ The program should ask the user to enter three test scores and then assign the values entered to the variables.
4
+ The program should display the average of the test scores and the letter grade that is assigned for the test score average.
5
+ Use the grading scheme in the following table:
6
+
7
+ Test Score Average Letter Grade
8
+ 90–100 A
9
+ 80–89 B
10
+ 70–79 C
11
+ 60–69 D
12
+ Below 60 F
13
+ */
14
+
15
+ package com .challenges ;
16
+
17
+ import java .util .Scanner ;
18
+
19
+ public class TestScoresAndGrade {
20
+ public static void main (String [] args ) {
21
+
22
+ // Declare Variables
23
+ double scoreOne ;
24
+ double scoreTwo ;
25
+ double scoreThree ;
26
+ double avg ;
27
+
28
+ Scanner scanner = new Scanner (System .in );
29
+
30
+ System .out .println ("Enter the first test score: " );
31
+ scoreOne = scanner .nextDouble ();
32
+
33
+ System .out .println ("Enter the second test score: " );
34
+ scoreTwo = scanner .nextDouble ();
35
+
36
+ System .out .println ("Enter the third test score: " );
37
+ scoreThree = scanner .nextDouble ();
38
+
39
+ avg = (scoreOne + scoreTwo + scoreThree ) / 3 ;
40
+
41
+ if (avg < 60 ) {
42
+ System .out .println ("The average is " + avg +". The grade is F." );
43
+ }
44
+ else if (avg < 70 ) {
45
+ System .out .println ("The average is " + avg +". The grade is D." );
46
+ }
47
+ else if (avg < 80 ) {
48
+ System .out .println ("The average is " + avg + ". The grade is C" );
49
+ }
50
+ else if (avg < 90 ) {
51
+ System .out .println ("The average is " + avg + ". The grade is B." );
52
+ }
53
+ else if (avg <= 100 ) {
54
+ System .out .println ("The average is " + avg + ". The grade is A." );
55
+ }
56
+ else {
57
+ System .out .println ("Something went wrong! Invalid Average." );
58
+ }
59
+ }
60
+ }
You can’t perform that action at this time.
0 commit comments