School Marks

... by Bittle in Programming Help March 18, 2019


Write a java method based program that uses and 2×2 array marks to store CAT 1 out of 10 CAT 2 out of 20 end main exam out of 70 marks for 8 course units of a student at the university

Array subject to store unit name and units code the marks are randomly generated

The unit name and codes are hard coded the program should then process the marks array to get the sum aggregate of all the marks

And the grade for each units

It should print out the performance score card of the student in the format shown


public class MainClass {

    public static void main(String[] args) {

        int number = 8;

        double[][] marks = new double[number][];

        for (int x = 0; x < number; x++) {
            double cat1 = Math.random() * 10;
            double cat2 = Math.random() * 20;
            double exam = Math.random() * 70;

            double total = cat1 + cat2 + exam;
            double grade = total / 3;
            marks[x] = new double[]{cat1, cat2, exam, total, grade};

        String[][] subject = {{"Name1", "Code1"}, {"Name2", "Code2"}, {"Name3", "Code3"}, {"Name4", "Code4"},
                {"Name5", "Code5"}, {"Name6", "Code6"}, {"Name7", "Code7"}, {"Name8", "Code8"}};

        System.out.printf("%-30s%-30s%-30s\n", "Student Number", "Name", "Date");
        System.out.printf("%-20s%-20s%-20s%-20s%-20s%-20s%-20s\n", "Unit Code", "Name", "Cat1", "Cat2", "Exam", "Aggregate", "Grade");

        for (int x = 0; x < number; x++) {
            System.out.printf("%-20s%-20s%-20.2f%-20.2f%-20.2f%-20.2f%-20.2f\n", subject[x][1], subject[x][0], marks[x][0], marks[x][1], marks[x][2], marks[x][3], marks[x][4]);

Comments (0)

Search Here