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

Write the following java application. Write the following java application. Defi

ID: 3668434 • Letter: W

Question

Write the following java application.

Write the following java application. Define a class Student which extends Person. It adds the attributes Int Testi, test2, test3 Double average String grade It has methods computeaverage() and calculategrade(). The grades are based on the average, with above 90 an A, 80 to 90 a B, 70 to 80 a C etc. All other attributes have a set and a get. Write an application that uses an array of type student of size 20. The program uses a menu that has options Enter the Students Enter grades for test 1 Enter grades for test 2 Enter grades for test 3 Calculate Grades List all Students final grades. Quit The application saves the data to a text file upon quitting and restores the data when it restarts

Explanation / Answer

import java.util.*;

class person
{
   protected String firstname;
   //protected attribute
   protected String lastname;
   //protected attribute
  
   void setfirstname(String fname)
   //sets first name
   {
       this.firstname = fname;
   }
   String getfirstname()
   //gets first name
   {
       return firstname;
   }
   void setlastname(String lname)
   //sets last name
   {
       this.lastname = lname;
   }
   String getlastname()
   //gets last name
   {
       return this.lastname;
   }
   person(String fname, String lname)
   //constructor for the person class
   {
       this.firstname = fname;
       this.lastname = lname;

   }
}
class student extends person
{
   private double hwave;
   private double quizave;
   private double projectave;
   private double testave;
   private double finalgrade;
   private String lettergrade;
   private String fullname;
   //all private variables
  
   void sethwave(int hw)
   // sets the homework average
   {
       this.hwave = hw;
   }
   double gethwave()
   //gets the homework average
   {
       return this.hwave;
   }
   void setquizave(int quizave)
   //sets the quiz average
   {
       this.quizave = quizave;
   }
   double getquizave()
   //gets the quiz average
   {
       return this.quizave;
   }
   void setprojectave(int projectave)
   //sets the project average
   {
       this.projectave = projectave;
   }
   double getprojectave()
   //gets the project average
   {
       return this.projectave;
   }
   void settestave(int testave)
   //sets the test average
   {
       this.testave = testave;
   }
   double gettestave()
   //gets the test average
   {
       return this.testave;
   }
   void setfinalgrade(int finalgrade)
   //sets the final average
   {
       this.finalgrade = finalgrade;
   }
   double getfinalgrade()
   //gets the final grade
   {
       return finalgrade;
   }
   void setlettergrade(String lettergrade)
   //sets the letter grade
   {
       this.lettergrade = lettergrade;
   }
   String getlettergrade()
   //gets the letter grade
   {
       return lettergrade;
   }
   String getfullname()
   //gets full name
   {

       fullname = getlastname() + "," + getfirstname();
       return fullname;
   }
  
   void calcfinal()
   //calclate the final percent and determine grade
   {
       this.finalgrade = ((quizave*.05)+(testave*.4)+(hwave*.15)+(projectave*.4));
       //formula for calculating the final grade
       if(finalgrade>=90)
       {
           lettergrade = "A";
       }
       else if(finalgrade>=80)
       {
           lettergrade = "B";
       }
       else if(finalgrade >= 70)
       {
           lettergrade = "C";
       }
       else if(finalgrade >=60)
       {
           lettergrade = "D";
       }
       else
       {
           lettergrade = "F";
       }
       //this determines the letter grade
   }
   void displaygrade()
   //this prints out the final grade and letter grade
   {
       System.out.println("Final grade: " + this.finalgrade + "% Letter grade: " + lettergrade);
   }
  
   student(String fname, String lname, int homework, int quiz, int project, int test)
   //this is a constructor for the student class
   {
       super(fname, lname);//call the attributes from the parent class
       setfirstname(fname);
       setlastname(lname);
       getfullname();
       sethwave(homework);
       setquizave(quiz);
       setprojectave(project);
       settestave(test);
       calcfinal();
   }
}

public class HelloWorld {


   public static void main(String[] args) {
      
       int choice = 0;
       int icount = 0;
       int numofstud;
       int hwave;
       int qave;
       int pave;
       int tave;
       String studfname;
       String studlname;
       Scanner oscan = new Scanner(System.in);
       boolean bsearch = true;
       //declare all variables
       student aostud[] = null;
       //declare the student array
      
       do
       //this is a loop for the menu
       {
           System.out.println(" Choose an option: 1. New Class List 2. Search for a Student 3. Exit ");
           choice = oscan.nextInt();
           //this prints the menu and inputs the answer
          
          
           if(choice == 1)
           //this is what happens for option 1
           {
               System.out.println("Enter the number of students");
               numofstud = oscan.nextInt();
               aostud = new student[numofstud];
               //this iniciates the array for the number of students
               for(icount = 0; icount< numofstud; icount++)
               //this loop goes until the array is full
               {
                   System.out.println("Enter info for Student " + (icount+1));
                   System.out.println("What is the students first name?");
                   oscan.nextLine();
                   studfname = oscan.nextLine();
                   System.out.println("What is the student's last name?");
                   studlname = oscan.nextLine();
                   System.out.println("Enter mark for test1");
                   hwave = oscan.nextInt();
                   System.out.println("Enter mark for test2");
                   qave = oscan.nextInt();
                   System.out.println("Enter mark for test3?");
                   pave = oscan.nextInt();
                   System.out.println("Enter mark for test4?");
                   tave = oscan.nextInt();
                   //this prompts the user for all the student information and assigns to variables
                  
                   aostud[icount]= new student(studfname, studlname, hwave, qave, pave, tave);
                   //call the student constructor
               }
           }  
           if(choice == 2)
           {
               String fname;
               String lname;
               icount = 0;
               bsearch = true;
               //declare variables
              
               oscan.nextLine();
               // clear the buffer
              
               System.out.println("Enter a Students last name: ");
               lname = oscan.nextLine();
               System.out.println("Enter a students first name: ");
               fname = oscan.nextLine();
               //ask for first and last name to search the array

               for (icount= 0;(bsearch == true) && (icount < aostud.length); icount ++)
               {
                   if ((aostud[icount].getlastname().equalsIgnoreCase(lname)) && (aostud[icount].getfirstname().equalsIgnoreCase(fname)))
                   // if the last and first name match, then print the students grades
                   {
                       System.out.println(aostud[icount].getfullname());
                       aostud[icount].displaygrade();
                       bsearch = false;
                       //set bsearch to false to end the loop
                   }
                   else if(icount == (aostud.length - 1))
                   //prints out an error if the student doesn't exist
                   {
                       System.out.println("Student does not exist");
                   }
               }              
           }
          
       }while (choice != 3);
       //if the option is not 3, the loop will continue
   }
}


Sample output
                                                                                                                
Choose an option:                                                                                                                                           
1.      New Class List                                                                                                                                      
2.      Search for a Student                                                                                                                                
3.      Exit                                                                                                                                                
                                                                                                                                                            
1                                                                                                                                                           
Enter the number of students                                                                                                                                
2                                                                                                                                                           
Enter info for Student 1                                                                                                                                    
What is the students first name?                                                                                                                            
ram                                                                                                                                                         
What is the student's last name?                                                                                                                            
chand                                                                                                                                                       
Enter mark for test1                                                                                                                                        
45                                                                                                                                                          
Enter mark for test2                                                                                                                                        
50                                                                                                                                                          
Enter mark for test3?                                                                                                                                       
55                                                                                                                                                          
Enter mark for test4?                                                                                                                                       
60