user3479783
user3479783

Reputation: 69

Displaying an individual student's mark

I have to make a program that gathers the total number of assignments and the students mark for each assignment. The program returns each student's mark for the assignments. This is my output window right now:

How many students are in the class? 2 User input = assignmentLimit

How many assignments did you assign? 2 User input = studentLimit

Assigment 1 marks:

Student 1: 41 User input

Student 2: 52 User input

Assigment 2 marks:

Student 1: 74 User input

Student 2: 85 User input

Student 1 marks

41.0

52.0

Student 2 marks

74.0

85.0

But under the student 1 marks section, I want it to display 41.0 and 74.0. For Student 2 marks, I want to display 52.0 and 85.0. How would I do this? This is section that gathers and displays the marks:

double[][] mark = new double[assignmentLimit][studentLimit];
    for (index = 0; index < assignmentLimit; index++)
    {
        System.out.println("\nAssigment " + (index + 1) + " marks:");
        for (int studentMark = 0; studentMark < studentLimit; studentMark++)
        {
            System.out.print("\nStudent " + (studentMark + 1) + ": ");
            mark[index][studentMark] = Integer.parseInt(console.readLine());
        } // end of for(int index = 0; index < ARRAY_LIMIT; index++)
    }

    for (index = 0; index < studentLimit; index++)
    {  
        System.out.println("\nStudent " + (index + 1) + " marks");
        for (int studentMark = 0; studentMark < assignmentLimit; studentMark++)
        {
            System.out.println("\t" + mark[index][studentMark]);
        }
    }

Upvotes: 0

Views: 162

Answers (2)

Md Editz
Md Editz

Reputation: 1

import java.util.Scanner;
public class CWH_05_TakingInput {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // Student Marks Input

        System.out.println("Enter a Hindi Marks");
        int hindi = sc.nextInt();
        System.out.println("Enter a English Marks");
        int english = sc.nextInt();
        System.out.println("Enter a Math Marks");
        int math = sc.nextInt();
        System.out.println("Enter a Physics Marks");
        int physics = sc.nextInt();
        System.out.println("Enter a Biology Marks");
        int biology = sc.nextInt();
        System.out.println("Enter a Chemistry Marks");
        int chemistry = sc.nextInt();

        //Total Subject Calculation

        int total = hindi+english+math+physics+biology+chemistry;

        //Function

        System.out.println("Hindi : " +hindi);
        System.out.println("English : " +english);
        System.out.println("Math : " +math);
        System.out.println("Physics : " +physics);
        System.out.println("Biology : " +biology);
        System.out.println("Chemistry : " +chemistry);

        System.out.println("Your Total Marks = "+total);

      int percentage = (total/6);

      System.out.println("The Percentage is = "+percentage+"%");

// Function for Pass or Fail

      if (hindi>40 && english>40){
          System.out.println("Pass");
      }
      else if (math>40 && physics>40) {
          System.out.println("Pass");

      } else if (biology>40 && chemistry>40) {
          System.out.println("Pass");

      }
      else {
          System.out.println("Fail");
      }

    }
}

Upvotes: 0

Leo Zhao
Leo Zhao

Reputation: 544

Try this:

double[][] mark = new double[assignmentLimit][studentLimit];
    for (index = 0; index < assignmentLimit; index++)
    {
        System.out.println("\nAssigment " + (index + 1) + " marks:");
        for (int studentMark = 0; studentMark < studentLimit; studentMark++)
        {
            System.out.print("\nStudent " + (studentMark + 1) + ": ");
            mark[index][studentMark] = Integer.parseInt(console.readLine());
        } // end of for(int index = 0; index < ARRAY_LIMIT; index++)
    }

    for (index = 0; index < studentLimit; index++)
    {  
        System.out.println("\nStudent " + (index + 1) + " marks");
        for (int studentMark = 0; studentMark < assignmentLimit; studentMark++)
        {
            System.out.println("\t" + mark[studentMark][index]); // mark[studentMark][index] but not mark[index][studentMark]
        }
    }

Upvotes: 1

Related Questions