-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode 52 Group 1.txt
149 lines (122 loc) · 4.31 KB
/
code 52 Group 1.txt
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* Program: code 32 question 1
* Date: 21/5/2019
* Programmer: J.Sookha
* Description:
*/
package code32question1;
import java.util.Scanner;
public class code32question1{
static int intNumOfStudents;
public static void main(String[] args){
intNumofStudents = 2; // suppose to be 15
String[] strStudentNum = new String[intNumofStudents];
int[] intTestMark = new int[intNumofStudents];
String[] strGrade = new String[intNumofStudents];
String[] strTestAns = new String[10];
strTestAns = loadTestAns();
int intRightCount;
intRightCount = 0;
String strAns;
strAns = "";
//System.out.println(strTestAns[9]);
Scanner sc = new Scanner(System.in);
for (int intCount = 0; intCount <= (intNumofStudents - 1); intCount++){
System.out.print("Enter the Student Number [" + (intCount + 1) + "] - ");
strStudentNum[intCount] = sc.nextLine();
intRightCount = 0;
for (int intCount2 = 0; intCount2 <= 9; intCount2++){
System.out.print("Answer to Question [" + (intCount2 + 1) + "] - ");
strAns = sc.nextLine();
if (strTestAns[intCount2].equals(strAns)){
intRightCount = intRightCount + 1;
}
}
intTestMark[intCount] = intRightCount;
}
strGrades = CalcGrades(intTestMark);
PrintStudInfo(strStudentNum, intTestMark, strGrades);
}
public static void PrintStudInfo(String[] strStudent, int[] intMarks, String[] strGrade){
double dblPerc;
dblPerc = 0.0;
System.out.println(String.format("%-10s %-10s %-10s %-10s","Student #", "Mark", "Percent", "Grade"));
for (int intCount = 0; intCount <= (intNumofStudents - 1); intCount++){
dblPerc = (intMarks[intCount] / 10 ) * 100;
System.out.println(String.format("%-10s %-10s %-10s %-10s",strStudent[intCount], intMarks[intCount], dblPerc, strGrade[intCount]));
}
}
public static String[] CalcGrades(int[] intMarks){
String[] strTheseGrades = new String[2];
double dblPerc;
dblPerc = 0.0;
for (int intCount = 0; intCount <= (intNumofStudents - 1); intCount++){
dblPerc = (intMarks[intCount] / 10) * 100;
if (dblPerc >= 80)
strTheseGrades[intCount] = "A";
else
if (dblPerc >= 70)
strTheseGrades[intCount] = "B";
else
if (dblPerc >= 60)
strTheseGrades[intCount] = "C";
else
if (dblPerc >= 50)
strTheseGrades[intCount] = "D";
else
strTheseGrades[intCount] = "F";
}
return strTheseGrades;
}
public static String[] loadTestAns(){
String[] strAns = new String[10];
strAns[0] = "true";
strAns[1] = "true";
strAns[2] = "false";
strAns[3] = "true";
strAns[4] = "false";
strAns[5] = "true";
strAns[6] = "false";
strAns[7] = "false";
strAns[8] = "true";
strAns[9] = "false";
return strAns;
}
}
/*
1. Mr. Jones always gives True/False tests to his class. His tests always have 10 questions.
The maximum class size is 15. He needs a program that will calculate and output
each student’s number, their total score/percentage for a test and their grade. You are
also required to output the lowest and highest mark/percentage along with the student number
associated to those marks
Develop a solution for Mr. Jones’s problem. The following 1-dimensional arrays are needed
Variable Description Size
strStudentNum to store the student numbers 15
intTestMark to store the total mark for a test for a student 15
strGrade to store the grade equivalent to the mark received 15
strTestAns to store the correct answers for the test 10
When inputting the student's details, you are required to input each student's set of
answers for the 10 questions in the test. Using the strTestAns array, you need to compare
the input to the answers stated in the array. Accumulate the total mark of all correct answers
and store this mark in the intTestMark array.
Store the following values for the strTestAns array, to be used for the comparison to the
student's set of answers
Question Answer
1 true
2 true
3 false
4 true
5 false
6 true
7 false
8 false
9 true
10 false
Using the intTestMark (total mark), store the student's grade using the following information
Percentage Grade
80 - 100 A
70 - 79 B
60 - 69 C
50 - 59 D
< 50 F
*/