Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(java programing) Create a program to enter grades and calculate averages and le

ID: 653948 • Letter: #

Question

(java programing)

Create a program to enter grades and calculate averages and letter grades. 1. Need a class which will contain: a. Student Name b. Student Id c. Student Grades (an array of 3 grades) d. A constructor that clears the student data (use -1 for unset grades) e. Get functions for items a, b, and c, average, and letter grade f. Set functions for items a, n, and c g. Note that the get and set functions for Student grades need an argument for the grade index. 2. Need another class which will contain: a. An Array of Students (1 above) b. A count of number of students in use 3. You need to create a menu interface that allows you to: a. Add new students b. Enter test grades c. Display all the students with their names, ids, test grades, average, and letter grade d. Exit the program 4. Add comments and use proper indentation.

Explanation / Answer

// Student.java

public class Student{
   String name;
   int id;
   int grades[] = new int[3];
   Student(){
       name = "";
       id = -1;
       for(int i = 0; i < 3; i++) grades[i] = -1;
   }
   String getName(){
       return name;
   }
   int getId(){
       return id;
   }
   int getGrade(int index){
       return grades[index];
   }
   double getAverage(){
       double avg = 0;
       for(int i = 0; i < 3; i++) avg += grades[i];
       avg /= 3.0;
       return avg;
   }
   String getLetterGrade(){
       if(getAverage() >= 90) return "A";
       else if(getAverage() >= 80) return "B";
       else if(getAverage() >= 70) return "C";
       else if(getAverage() >= 60) return "D";
       else if(getAverage() >= 50) return "E";
       else return "F";
   }
   void setName(String n){
       name = n;
   }
   void setId(int i){
       id = i;
   }
   void setGrades(int g, int index){
       grades[index] = g;
   }
}

// test.java

import java.util.Scanner;
public class test{
   public static void main(String args[]){
       Scanner in = new Scanner(System.in);
       Student array[] = new Student[100];
       int count = 0, choice;
       String name;
       while(true){
           System.out.print("Menu 1. Add new student 2. Enter test grade 3. Display all the students 4. Exit the program Enter your choice(1, 2, 3 or 4): ");
           choice = in.nextInt();
           switch(choice){
           case 1:
               array[count] = new Student();
               array[count].setId(count + 1);
               System.out.print("Enter the student's name: ");
               name = in.next();
               array[count].setName(name);
               System.out.print("Enter 3 grades for the student: ");
               for(int i = 0; i < 3; i++){
                   int temp = in.nextInt();
                   array[count].setGrades(temp, i);
               }
               count++;
               break;
           case 2:
               System.out.print("Enter the student's name to enter grades: ");
               name = in.next();
               int nameIndex = 0;
               for(int i = 0; i < count; i++){
                   if(name.equalsIgnoreCase(array[i].getName())) nameIndex = i;
               }
               System.out.print("Enter 3 new grades for the student: ");
               for(int i = 0; i < 3; i++){
                   int temp = in.nextInt();
                   array[count].setGrades(temp, i);
               }
               break;
           case 3:
               for(int i = 0; i < count; i++){
                   System.out.println("ID: " + array[i].getId() + ", Name: " + array[i].getName() + ", Average: " + array[i].getAverage() + ", Grade: " + array[i].getLetterGrade());
               }
               break;
           case 4:
               return;
           }
       }
   }
}