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
36 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
Answered By
8 Likes
Related Questions
A double dimensional array is defined as N[4][4] to store numbers. Write a program to find the sum of all even numbers and product of all odd numbers of the elements stored in Double Dimensional Array (DDA).
Sample Input:12 10 15 17 30 11 32 71 17 14 29 31 41 33 40 51
Sample Output:
Sum of all even numbers: ……….
Product of all odd numbers: ……….A Departmental Shop has 5 stores and 6 departments. The monthly sale of the department is kept in the Double Dimensional Array (DDA) as m[5][6]. The Manager of the shop wants to know the total monthly sale of each store and each department at any time. Write a program to perform the given task.
(Hint: Number of stores as rows and Number of departments as columns.)A Metropolitan Hotel has 5 floors and 10 rooms in each floor. The names of the visitors are entered in a Double Dimensional Array (DDA) as M[5][10].The Hotel Manager wants to know from the "Enquiry" about the position of a visitor (i.e. floor number and room number) as soon as he enters the name of the visitor. Write a program in Java to perform the above task.
If arrays M and M + N are as shown below, write a program in Java to find the array N.
M = {{-1, 0, 2}, M + N = {{-6, 9, 4}, {-3, -1, 6}, {4, 5, 0}, {4, 3, -1}} {1, -2, -3}}