-
Notifications
You must be signed in to change notification settings - Fork 0
/
FiveScores.java
114 lines (98 loc) · 2.78 KB
/
FiveScores.java
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
108
109
110
111
112
113
114
//The program compiles in the Terminal with five integers entered after filename
//cd into the folder where the file is to be run
//compile the file by using the following command:
//javac filename.java
//input the following command to test the program:
//java fiveScores 70 80 80 90 70
//output should be the following:
//Your score grades: C B B A C
//Your final score and grade: 78.0 C
//input range for 'scores' placed after the filename is 0 - 100
import java.util.Scanner;
public class FiveScores
{
Scanner input = new Scanner(System.in);
String [] args = {input.nextLine(), input.nextLine(), input.nextLine(), input.nextLine(), input.nextLine()};
public static void main (String[]args)
{
int [] array = new int [5];
int [] scores = new int [5];
int grade = 0;
setGrades(args, array);
for(int i = 0; i < 1; i++)
{
if((array[0] + array[1] + array[2] + array[3] + array[4]) != 0)
{
System.out.print("\nYour score grades: " + determineGrade(array[0]));
System.out.print(" " + determineGrade(array[1]));
System.out.print(" " + determineGrade(array[2]));
System.out.print(" " + determineGrade(array[3]));
System.out.print(" " + determineGrade(array[4]));
grade = ((array[0] + array[1] + array[2] + array[3] + array[4])/5);
System.out.print("\nYour final score and grade: " + calcAverage(array));
System.out.print(" " + determineGrade(grade));
System.out.print("\n\n");
}
}
}
public static boolean setGrades(String args[], int [] array)
{
Scanner input = new Scanner(System.in);
int [] copyArray = new int [5];
for(int i = 0; i < args.length; i++)
{
copyArray[i] = Integer.parseInt(args[i]);
}
for(int i = 0; i < array.length; i++)
{
if(copyArray[0] <= 100 &&
copyArray[1] <= 100 &&
copyArray[2] <= 100 &&
copyArray[3] <= 100 &&
copyArray[4] <= 100 &&
copyArray[0] >= 0 &&
copyArray[1] >= 0 &&
copyArray[2] >= 0 &&
copyArray[3] >= 0 &&
copyArray[4] >= 0 &&
array.length == args.length)
{
array[i] = copyArray[i];
}
}
return false;
}
public static double calcAverage(int [] scores)
{
double average = 0;
double sum;
sum = (scores[0] + scores[1] + scores[2] + scores[3] + scores[4]);
average = (sum / scores.length);
return average;
}
public static char determineGrade(int integer)
{
char letterGrade = 0;
if(integer < 0 || integer <= 59)
{
letterGrade = 'F';
}
else if(integer < 60 || integer <= 69)
{
letterGrade = 'D';
}
else if(integer < 70 || integer <= 79)
{
letterGrade = 'C';
}
else if(integer < 80 || integer <= 89)
{
letterGrade = 'B';
}
else if(integer < 90 || integer <= 100)
{
letterGrade = 'A';
}
return letterGrade;
}
}