Programming in Java Write a program that will take 10 values representing exam s
ID: 3925746 • Letter: P
Question
Programming in Java
Write a program that will take 10 values representing exam scores (0-100) for a student. Then display a menu.
1 - display Ave score for Student
2 - display exam with the highest score
3 - display exam with the lowest score
4 - display all exam scores
0 - exit
REQUIREMENTS:
1. user-defined class (student_exam_info)
2. use loops, ifs, switch
3. use methods for each menu item
4. error check all entries (menu selections and score entries
Last modified: Wednesday, October 12, 2016, 6:36 AM
Explanation / Answer
package chegg;
import java.util.Scanner;
public class Student_exam_info {
// // method for display Ave score for Student
void ave_score_for_Student(int a[])
{
int sum=0;
float average=0;
for(int i=0;i<10;i++)
{
sum=sum+a[i];
}
average=sum/10;
System.out.println("Ave_score_for_Student is: "+average);
}
// method for display exam with the highest score
void higest_score(int a[])
{
int max=0;
for ( int i = 0 ; i < 10 ; i++ )
{
if ( a[i] > max )
{
max = a[i];
}
}
System.out.println("Exam with the highest score is :" + max);
}
// method for display exam with the lowest score
void lowest_score(int a[])
{
int min=a[0];
for ( int i = 0 ; i < 10 ; i++ )
{
if ( a[i] < min )
{
min = a[i];
}
}
System.out.println("Exam with the Lowest score is :" + min);
}
// method for display all exam scores
void exam_score(int a[])
{
System.out.println("Exam score is :-");
for ( int i = 0 ; i < 10 ; i++ )
{
System.out.println("exam score " +(i+1)+ " is :"+ a[i]);
}
}
// method for program exit
void exit()
{
System.out.println("your program exited");
return ;
}
public static void main(String[] args) {
boolean t=true;
Scanner sc = new Scanner(System.in);
int value[]=new int[10];
System.out.println("Eneter values representing exam scores(0-100)"); // read 10 input from keyborad
for(int i=0;i<10;i++)
{
value[i]=sc.nextInt();
if(value[i] >=0 && value[i] <=100)
{
}
else{
t=false;
}
}
while(t==false)
{
System.out.println("Enetered values for representing exam scores is not in range(0-100)");
return ;
}
System.out.println("1 - display Ave score for Student "+
"2 - display exam with the highest score " +
"3 - display exam with the lowest score "+
"4 - display all exam scores "+
"0 - exit");
System.out.print("Enter your Choice Menu ");
int choice = sc.nextInt();
Student_exam_info student= new Student_exam_info();
switch (choice) {
case 1: student.ave_score_for_Student(value);
break;
case 2:student.higest_score(value);
break;
case 3: student.lowest_score(value);
break;
case 4: student.exam_score(value);
break;
case 0: student.exit();
break;
default: System.out.println("Select valid Menu.");break;
} // end of switch loop
}// end of main method
} // end of Student_exam_info class
=========================================================================
output 1:-
Eneter values representing exam scores(0-100)
2
5
8
5
4
3
6
8
9
6
1 - display Ave score for Student
2 - display exam with the highest score
3 - display exam with the lowest score
4 - display all exam scores
0 - exit
Enter your Choice Menu 9
Error: - Select valid Menu option
-----------------------------------
Eneter values representing exam scores(0-100)
5
6
9
5
3
5
0
-8
3
5
Enetered values for representing exam scores is not in range(0-100)
------------------------
Eneter values representing exam scores(0-100)
5
77
88
44
22
1
99
77
6
55
1 - display Ave score for Student
2 - display exam with the highest score
3 - display exam with the lowest score
4 - display all exam scores
0 - exit
Enter your Choice Menu 1
Ave_score_for_Student is: 47.0
----------------------------------------
Eneter values representing exam scores(0-100)
3
5
7
9
5
4
3
2
5
67
1 - display Ave score for Student
2 - display exam with the highest score
3 - display exam with the lowest score
4 - display all exam scores
0 - exit
Enter your Choice Menu 2
Exam with the highest score is :67
------------------------
Eneter values representing exam scores(0-100)
1
55
66
77
88
99
33
46
86
32
1 - display Ave score for Student
2 - display exam with the highest score
3 - display exam with the lowest score
4 - display all exam scores
0 - exit
Enter your Choice Menu 3
Exam with the Lowest score is :1
-------------------------------------------------------------------------
Eneter values representing exam scores(0-100)
3
5
7
8
55
33
22
55
88
66
1 - display Ave score for Student
2 - display exam with the highest score
3 - display exam with the lowest score
4 - display all exam scores
0 - exit
Enter your Choice Menu 4
Exam score is :-
exam score 1 is :3
exam score 2 is :5
exam score 3 is :7
exam score 4 is :8
exam score 5 is :55
exam score 6 is :33
exam score 7 is :22
exam score 8 is :55
exam score 9 is :88
exam score 10 is :66
--------------------------------------------------------
If you have any query, please feel free to ask
Thanks a lot
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.