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

Please help me. Question 3: Student Class Design, draw UML diagram, and implemen

ID: 643183 • Letter: P

Question

Please help me.

Question 3: Student Class

Design, draw UML diagram, and implement a Java class called Studentthat represents a student and some grades. The class should include the following five instance variables: ? firstName

? lastName

? test1Grade

? test2Grade

? test3Grade

Provide the following methods:

? A constructor that sets all instance values based on parameter values.

? Overload the constructor such that each test score is assumed to be initially zero.

? A method called setTestScore that accepts two parameters, the test number (1 through 3) and the score. For example, setTestScore(1,90) means set test 1 grade to 90.

? A method called getTestScore that accepts the test number and returns the appropriate score. For example, getTestScore(1) returns test 1 grade.

? A method called average that computes and returns the average test score for this student.

? toString method that displays the Student name, test scores, and average score.

Write a test application named StudentDriver that demonstrates Student capabilities.

Explanation / Answer


/**
* student class that has instance variables
* for first name, last name, test scores for
* three test values ang have methods that
* sets the test scores and returns the test
* scores and average finds the average
* of test scores.
* */
//Student.java
public class Student
{
   private String firstName;
   private String lastName;
   private int test1Grade;
   private int test2Grade;
   private int test3Grade;
  
   //Default constructor
   public Student()
   {
       firstName="";
       lastName="";
       test1Grade=0;
       test2Grade=0;
       test3Grade=0;
   }
  
   //parameterized constructor
  
   public Student(String firstName,String lastName,
           int test1Name, int test2Name, int test3Name)
   {
       this.firstName=firstName;
       this.lastName=lastName;
       this.test1Grade=test1Name;
       this.test2Grade=test2Name;
       this.test3Grade=test3Name;
   }
   //Method to ste the test score
   public void setTestScore(int testNumber, int score)
   {
       if(testNumber==1)
           test1Grade=score;
       else if(testNumber==2)
           test1Grade=score;
       else if(testNumber==3)
           test1Grade=score;
          
   }
  
   //The method getTestScore that accpts the test number
   //and returns the test grade .
   public int getTestScore(int testNumber)
   {
       if(testNumber==1)
           return test1Grade;
       else if(testNumber==2)
           return test1Grade;
       else if(testNumber==3)
           return test1Grade;
       return testNumber;
          
   }
  
   //The method average returns the average score of three
   //test scores.
   public double average()
   {
       return (test1Grade+test2Grade+test3Grade)/3.0;
   }
  
   //Overrides the toString method that displays the name
   //test scores and average
   @Override
   public String toString()
   {      
       //returns string representation of
       //Student class
       return "NAME : "+firstName+" "+lastName+
               "TEST SCORE1 : "+test1Grade+" "+
               "TEST SCORE2 : "+test2Grade+" "+
               "TEST SCORE3 : "+test3Grade+" "+
               "AVERAGE SCORE : "+average();
      
   }
  
}


---------------------------------------------------------------------------------------------------------------------------------------


//Test program of Student class
//StudentDriver.java
public class StudentDriver
{

   public static void main(String[] args)
   {
       //Create an instance of Student class
       Student student=new Student();      
       System.out.println(student);

       //set student score using setTestScore       
       student.setTestScore(1, 100);
       //set student score using setTestScore       
       student.setTestScore(2, 100);
       //set student score using setTestScore       
       student.setTestScore(3, 100);
      
       //call getTestScore methods to display the test scors.
      
       System.out.println("Test Score 1: "+student.getTestScore(1));
       System.out.println("Test Score 2: "+student.getTestScore(2));
       System.out.println("Test Score 3: "+student.getTestScore(3));
      
       //Call the method average       
       System.out.println("Average of student test scores : "+
               student.average());

       //Display string represenation using toString method
       System.out.println(student.toString());

       //Create a parameterized cosntructor

       Student studentObject=new Student("John", "Dietel", 99, 99, 99);      
       System.out.println(studentObject);

   }
}


-----------------------------------------------------------------------------------------------------------------------------------------------------------

Sample output:

NAME : TEST SCORE1 : 0
TEST SCORE2 : 0
TEST SCORE3 : 0
AVERAGE SCORE : 0.0
Test Score 1: 100
Test Score 2: 100
Test Score 3: 100
Average of student test scores : 33.333333333333336
NAME : TEST SCORE1 : 100
TEST SCORE2 : 0
TEST SCORE3 : 0
AVERAGE SCORE : 33.333333333333336
NAME : John DietelTEST SCORE1 : 99
TEST SCORE2 : 99
TEST SCORE3 : 99
AVERAGE SCORE : 99.0

Hope this helps you

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote