-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiThreading2.java
More file actions
71 lines (66 loc) · 1.66 KB
/
MultiThreading2.java
File metadata and controls
71 lines (66 loc) · 1.66 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
// Thread 2
public class MultiThreading2 extends Thread{
@Override
public void run()
{
// Initialize variables and array
int Grades[] = {67, 58, 98, 75, 91, 83, 98, 76};
int aCount = 0, bCount = 0, cCount = 0, dCount = 0, fCount = 0;
// Loop through grades and assign each one a letter grade
for(int i = 0; i <= Grades.length - 1; i++)
{
System.out.println(Grades[i]);
if(Grades[i] <= 100 && Grades[i] >= 90)
{
System.out.println('A');
aCount++;
}
else if(Grades[i] >= 80)
{
System.out.println('B');
bCount++;
}
else if(Grades[i] >= 70)
{
System.out.println('C');
cCount++;
}
else if(Grades[i] >= 60)
{
System.out.println('D');
dCount++;
}
else
{
System.out.println('F');
fCount++;
}
// Pause in between each iteration
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
// Find which counter is the highest and output results
if(aCount > bCount && aCount > cCount && aCount > dCount && aCount > fCount)
{
System.out.println("There are more A's than any other grade");
}
else if(bCount > aCount && bCount > cCount && bCount > dCount && aCount > fCount)
{
System.out.println("There are more B's than any other grade");
}
else if(cCount > aCount && cCount > bCount && cCount > dCount && aCount > fCount)
{
System.out.println("There are more C's than any other grade");
}
else if(dCount > aCount && dCount > bCount && dCount > cCount && aCount > fCount)
{
System.out.println("There are more D's than any other grade");
}
else
{
System.out.println("There are more F's than any other grade");
}
}
}