Write a program that does the following: 1. Uses a menu system 2. Creates an array with 25 rows and an unknow number of columns 3. You can assume that the row index represents one individual student 4. Each column represents an exam score for that individual student (the number of exams will vary by student) 5. Enter at least 10 students along with a varying number of exam scores for each different student. 6. Display the Average for all exams by each Student Id 7. Display the Average for each exam by Exam Number 8. Display the class average 9. Everything needs to be a written in Static Method 10. Do not forget your design tool The menu system will have an option to input grades for the next student. Once pressed the user will then enter how many exams that student has taken. The program will then ask the user to enter each of those exam scores. Menu will have an option to display the exam average by student. Menu will have an option to display the exam average by exam. Menu will have an option to display the current class average for all exams.

Respuesta :

Answer:

import java.util.Scanner;

/**

*

* @author pc

*/

public class JaggedARrayAssignment {

private static int students[][] = new int[25][];//create a jagged array having 25 rows and unknown columns

public static void menu()

{

int index=0;//intitalize number of students to zero intially

Scanner sc=new Scanner(System.in);// create scanner for taking input from user

int choice;//choice

int maxExams=0;//maximum number of exams taken by any student

do

{

//print the menu

System.out.println("1-Input grades for next student");

System.out.println("2-Display the exam Average by student");

System.out.println("3-Display the exam Average by exam");

System.out.println("4-Display the current class average for all exams");

System.out.println("5-Exit");

choice=sc.nextInt();

//if choice is 1

if(choice==1)

{//ask how many xams

System.out.println("Please enter how many exams this student has taken?");

int noOfExams=sc.nextInt();//take input

students[index]=new int[noOfExams];//intialize array index by no of exams

System.out.println("Please enter the each of those exam scores one by one");//enter scores

if(maxExams<noOfExams)//if this noofexams is greater then update maxexams

maxExams=noOfExams;

//take scores from user

for(int i=0;i<noOfExams;i++)

{

students[index][i]=sc.nextInt();

}

index++;//increase index

}

else if(choice==2)

{

//calculate avregage by student and print it

System.out.println("*** Average by Student Id ***");

System.out.println("Student Id\tAverage Score");

for(int i=0;i<index;i++)

{

System.out.print((i+1)+"\t");//print student id

int sum=0;

//calculate sum

for(int j=0;j<students[i].length;j++)

{

sum=sum+students[i][j];

}

double avg=sum*1.0/students[i].length;//find average

System.out.printf("%.2f",avg);//print average by precison of two

System.out.println();

}

}

else if(choice==3)

{//caculate averag eby exams and print it

System.out.println("*** Average by Exam Number ***");

System.out.println("Exam Number\tAverage Score");

for(int i=0;i<maxExams;i++)

{

int sum=0,total=0;

for(int j=0;j<index;j++)

{

if(students[j].length>=i+1)

{

total++;

sum=sum+students[j][i];

}

}

double avg=sum*1.0/total;

System.out.print((i+1)+"\t");

System.out.printf("%.2f",avg);

System.out.println();

}

}

else if(choice ==4)

{//find iverall average

int sumtotal=0;

for(int i=0;i<index;i++)

{

int sum=0;

for(int j=0;j<students[i].length;j++)

{

sum=sum+students[i][j];

}

double avg=sum*1.0/students[i].length;

sumtotal+=avg;

}

double avgTotal=sumtotal*1.0/index;

System.out.println("Current class Average for all exams - "+avgTotal);

}

}while(choice!=5);

}

public static void main(String[] args) {

menu();

}

}