2. Create a java program that initialize a two dimensional array with the continuous assessment marks used to determine the semester mark for PRG510S exam qualification, The system should also create an array of student names in correspondence to the marks (Note: the appropriate weights of each individual assessment are given under corresponding headings and both the marks and student names are read from the user input).
test1
(Weight 20%)
test2
(Weight 20%)
labs
(Weight 20%)
in_class
exercise
(Weight 10%)
assignment
(Weight 30%)
John
50
60
79
89
63
Harry
41
52
68
56
40
Uushona
30
20
52
38
47
Sililo
23
33
45
19
27
Enter class size: 4
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter class size: ");
int size = in.nextInt();
String[] names = new String[size];
int[][] marks = new int[size][5];
for (int i = 0; i < names.length; i++) {
System.out.print("Name: ");
names[i] = in.next();
for (int j = 0; j < marks[i].length; j++) {
System.out.print("Mark " + (j + 1) + ": ");
marks[i][j] = in.nextInt();
}
}
System.out.println("\nPRG510S");
System.out.printf("%-12s%-20s%-20s%-20s%-20s%-20s%-10s\n", "name", "test1", "test2", "labs",
"in_class exercises", "assignment", "total");
System.out.printf("%-12s%-20s%-20s%-20s%-20s%-20s\n", "", "(Weight 20%)", "(Weight 20%)", "(Weight 20%)",
"(Weight 10%)", "(Weight 30%)");
int total;
int[] weights = {20, 20, 20, 10, 30};
for (int i = 0; i < names.length; i++) {
System.out.printf("%-12s", names[i]);
total = 0;
for (int j = 0; j < marks[i].length; j++) {
System.out.printf("%-20s", marks[i][j]);
total += marks[i][j] * weights[j];
}
System.out.printf("%-10s\n", 0.01 * total);
}
}
}
Comments
Leave a comment