In: Computer Science
2. Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a student gradebook using a two-dimensional array. It should allow the user to enter the number of students and the number of assignments they wish to enter grades for. This input should be used in defining the two-dimensional array for your program. For example, if I say I want to enter grades for 4 students and 5 assignments, your program should define a 4 X 5 array. Your program should allow the user to then enter the appropriate number of grades and store them within the twodimensional array. Your program should include an additional method that will display these values in a matrix form, with the student names on the left and the assignment names as the column header. After displaying the matrix, add a second method that will display each student’s grade average.
import java.util.*;
class Test
{
public static void main (String[] args)
{
String[] name = new String[4];
int[][] assignment = new int[4][5];
int[] gradeAverage = new int[4];
Scanner scan = new Scanner(System.in);
for(int i=0;i<4;i++)
{
System.out.println("Enter name and 5 assignment marks for student
"+(i+1)+" : ");
name[i] = scan.next();
for(int j=0;j<5;j++)
{
assignment[i][j] = scan.nextInt();
}
}
print(name,assignment);
print(name,assignment,gradeAverage);
}
public static void print(String[] name,int[][] assignment)
{
System.out.println("\n\n\nName\tAssignment1\tAssignment2\tAssignment3\tAssignment4\tAssignment5");
for(int i=0;i<4;i++)
{
System.out.print(name[i]+"\t\t");
for(int j=0;j<5;j++)
{
System.out.print(assignment[i][j]+"\t\t");
}
System.out.println();
}
}
public static void print(String[] name,int[][] assignment,int[]
gradeAverage)
{
System.out.println("\n\n\nName\tGrade Average");
for(int i=0;i<4;i++)
{
gradeAverage[i] = 0;
System.out.print(name[i]+"\t\t");
for(int j=0;j<5;j++)
{
gradeAverage[i]= gradeAverage[i] + assignment[i][j];
}
System.out.print(gradeAverage[i]/5);
System.out.println();
}
}
}
Output:
Enter name and 5 assignment marks for student 1 : Adams 56 74 75 83 65 Enter name and 5 assignment marks for student 2 : Belk 73 71 76 88 55 Enter name and 5 assignment marks for student 3 : Caan 86 64 78 81 69 Enter name and 5 assignment marks for student 4 : Dunn 66 84 79 65 64 Name Assignment1 Assignment2 Assignment3 Assignment4 Assignment5 Adams 56 74 75 83 65 Belk 73 71 76 88 55 Caan 86 64 78 81 69 Dunn 66 84 79 65 64 Name Grade Average Adams 70 Belk 72 Caan 75 Dunn 71
Do ask if any doubt. Please upvote.