Create a program to enter grades and calculate average and letter grades. Need a
ID: 3798486 • Letter: C
Question
Create a program to enter grades and calculate average and letter grades. Need a class which will contain: Student Name Student Id Student Grades (an array of 3 grades) A constructor that clears the student data (use -1 for unset grades) Get functions for items a, b, and c, average, and letter grade Set functions for items a, n, and c Note that the get and set functions for Student grades need an argument for the grade index. Need another class which will contain: An Array of Students (1 above) A count of number of students in use You need to create a menu interface that allows you to: Add new students Enter test grades Display all the students with their names, ids, test grades, average, and letter grade Exit the program Add comments and use proper indentation. Nice Features: I would like that system to accept a student with no grades, then later add one or more grades, and when all grades are entered, calculate the final average or grade. I would like the system to display the students in alphabetical order (no matter what order they are entered in) Create a Student class that can perform the tasks requested Create an array of Student and loading it Modifying the data in that array Displaying results for all students Add Proper indentation, comments, and “Nice Features” items An example menu might be: Enter A to Add Students Enter B to Enter Test Grades Enter C to Display Results Enter D to Exit Program Please select A, B, C, or D: For item B, you will need to prompt the user to enter the test number and then enter the value for each student for that test (if there is a previous value, you should display it and if the user enters the empty string, not change the value).
Explanation / Answer
//This is Student class
package com.studentGrading;
public class Student {
String name;
int id;
int sum=0;
int gradeA;
int gradeB;
int gradeC;
double avg=0.0;
public Student(){
}
public Student(String name,int id){
this.name=name;
this.id=id;
}
public void getDisplay(){
System.out.println("Student Name is: "+name);
System.out.println("Student Id is: "+id);
System.out.println("Student grades Sum is: "+sum);
System.out.println("Student grades Average is: "+avg);
}
public void getAverage(int gradeA,int gradeB,int gradeC){
if((gradeA>0)&&(gradeA<=5)&&(gradeB>0)&&(gradeB<=5)&&(gradeC>0)&&(gradeC<=5)){
this.gradeA=gradeA;
this.gradeB=gradeB;
this.gradeC=gradeC;
sum=gradeA+gradeB+gradeC;
avg=sum/3;
}else{
System.out.println("Please enter grade value between 1 to 5");
}
}
}
package com.studentGrading;
import java.util.ArrayList;
import java.util.Scanner;
public class StudentTest1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<Student> al=new ArrayList<Student>();
Student s=null;
Scanner sc=new Scanner(System.in);
System.out.println(" Student Grading Operations ");
System.out.println("Enter A to Add Student");
System.out.println("Enter B to Enter Test Grade");
System.out.println("Enter C to Display Result");
System.out.println("Enter D to Exit");
while(true){
System.out.print("Enter your choice [A,B,C & D]: ");
String choice = sc.next();
switch (choice)
{
case "A" :
System.out.print("Enter the Student Name: ");
String name=sc.next();
System.out.print("Enter the Student Id: ");
int id=sc.nextInt();
s=new Student(name,id);
al.add(s);
break;
case "B" :
System.out.print("Enter first Test grade value Grading must be between 1 to 5: ");
int gradeA =sc.nextInt();
System.out.print("Enter second Test grade value Grading between 1 to 5: ");
int gradeB=sc.nextInt();
System.out.print("Enter third Test grade value Grading between 1 to 5: ");
int gradeC=sc.nextInt();
s.getAverage(gradeA, gradeB, gradeC);
break;
case "C" :
for(Student stu:al){
stu.getDisplay();
}
break;
case "D" :
System.out.println("Bye....THANK YOU");
System.exit(0);
break;
default :
System.out.println("Wrong Entry ");
break;
}
}
}
}
OUTPUT:
Student Grading Operations
Enter A to Add Student
Enter B to Enter Test Grade
Enter C to Display Result
Enter D to Exit
Enter your choice [A,B,C & D]: a
Wrong Entry
Enter your choice [A,B,C & D]: A
Enter the Student Name: AMIT
Enter the Student Id: 1
Enter your choice [A,B,C & D]: B
Enter first Test grade value Grading must be between 1 to 5: 5
Enter second Test grade value Grading between 1 to 5: 5
Enter third Test grade value Grading between 1 to 5: 5
Enter your choice [A,B,C & D]: A
Enter the Student Name: JON
Enter the Student Id: 2
Enter your choice [A,B,C & D]: B
Enter first Test grade value Grading must be between 1 to 5: 4
Enter second Test grade value Grading between 1 to 5: 4
Enter third Test grade value Grading between 1 to 5: 4
Enter your choice [A,B,C & D]: A
Enter the Student Name: MAC
Enter the Student Id: 3
Enter your choice [A,B,C & D]: B
Enter first Test grade value Grading must be between 1 to 5: 3
Enter second Test grade value Grading between 1 to 5: 3
Enter third Test grade value Grading between 1 to 5: 3
Enter your choice [A,B,C & D]: C
Student Name is: AMIT
Student Id is: 1
Student grades Sum is: 15
Student grades Average is: 5.0
Student Name is: JON
Student Id is: 2
Student grades Sum is: 12
Student grades Average is: 4.0
Student Name is: MAC
Student Id is: 3
Student grades Sum is: 9
Student grades Average is: 3.0
Enter your choice [A,B,C & D]: D
Bye
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.