KnowledgeBoat Logo

Computer Applications

A Class Teacher wants to keep the records of 40 students of her class along with their names and marks obtained in English, Hindi, Maths, Science and Computer Science in a Double Dimensional Array (DDA) as M[40][5]. When the teacher enters the name of a student as an input, the program must display the name, marks obtained in the 5 subjects and the total. Write a program in Java to perform the task.

Java

Java Arrays

35 Likes

Answer

import java.util.Scanner;

public class KboatDDAStudentRecord
{
    public static void main(String args[]) {
        final int TOTAL_STUDENTS = 40;
        final int TOTAL_SUBJECTS = 5;
        final String SUBJECT_NAMES[] = {"English", "Hindi", 
            "Maths", "Science", "Computer Science"};
        Scanner in = new Scanner(System.in);
        String names[] = new String[TOTAL_STUDENTS];
        int marks[][] = new int[TOTAL_STUDENTS][TOTAL_SUBJECTS];
        int i = 0, j = 0;
        
        for (i = 0; i < TOTAL_STUDENTS; i++) {
            System.out.println("Student " + (i + 1) + " details:");
            System.out.print("Name: ");
            names[i] = in.nextLine();
            for (j = 0; j < TOTAL_SUBJECTS; j++) {
                System.out.print("Enter marks in " + 
                    SUBJECT_NAMES[j] + ": ");
                marks[i][j] = in.nextInt();   
            }
            in.nextLine();
        }
        
        System.out.print("\nEnter name of the student to search: ");
        String studentName = in.nextLine();
        for (i = 0; i < TOTAL_STUDENTS; i++) {
            if (names[i].equals(studentName))
                break;
        }
        
        if (i == TOTAL_STUDENTS) {
            System.out.println("Record for " + studentName 
                + " not found");
        }
        else {
            System.out.println("Name: " + names[i]);
            int total = 0;
            for (j = 0; j < TOTAL_SUBJECTS; j++) {
                System.out.println("Marks in " + 
                    SUBJECT_NAMES[j] + ": " + marks[i][j]);
                total += marks[i][j];
            }
            System.out.println("Total Marks: " + total);
        }
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of A Class Teacher wants to keep the records of 40 students of her class along with their names and marks obtained in English, Hindi, Maths, Science and Computer Science in a Double Dimensional Array (DDA) as M[40][5]. When the teacher enters the name of a student as an input, the program must display the name, marks obtained in the 5 subjects and the total. Write a program in Java to perform the task.

Answered By

8 Likes


Related Questions