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

Please implement a CLASS encapsulating the concept of students. Please reference

ID: 3839528 • Letter: P

Question

Please implement a CLASS encapsulating the concept of students. Please reference Chapter 7. Each student must have the following 5 attributes (i.e., instance variables): a) private String studentID;//student's ID such as 1 b) private String lastName;//student's last name such as Doe c) private String firstName;//student's first name such as John d) private double gpa;//student's GPA such as 3.00 e) private String phoneNumber;//student's phone number such as 111-5428 Please declare the following 3 static variables with proper initial values: private static int countStudents = 0;//count the total number of students being constructed private static double totalGpa = 0.0;//total GPA sum of all students//don't use float private static double averageGpa = 0.0;//average GPA of all students//don't use float Please create one constructor, 5 accessors, and 5 mutators for this Student class. The constructor must do all the following properly: a) create a new student by assigning attributes with all the data arguments being passed b) countStudents++;//increment the student count by one c) update the current GPA total and average properly as follows: totalGpa += gpa; averageGpa = totalGpa/countStudents; d) call printStudentRecord to print the complete record for this new student Please also create the following 2 static methods: (a) toString - to form a student record properly for printing; (b) printStudentRecord - to print the student record in a nice format using toString method. Therefore, at least 13 methods are to be created by you. You may make some methods static for your convenience. Please write a loop asking the user to enter student id, last name, first name, GPA, and phone number. Then, you print the student record, and show the current student count, total GPA, and average GPA. Then, continue asking the user to enter next student's data. If the student id is zero, thank the user and stop your program nicely. You must test your program (as follows) in your static void main method. Another optional way (if you know how) is to write a client class to test your program accordingly. Your testing input and output should be as follows: Please enter student id, last name, first name, GPA, and phone number> 1 Doe John 3.0 111-5428 Student id: 1, Last Name: Doe, First Name: John, GPA: 3.00, Phone Number: 111-5428 Current Student Count: 1, Total GPA: 3.00, Average GPA: 3.00 Please enter student id, last name, first name, GPA, and phone number> 2 Smith Mary 4.0 222-5555 Student id: 2, Last Name: Smith, First Name: Mary, GPA: 4.00, Phone Number: 222-5555 Current Student Count: 2, Total GPA: 7.00, Average GPA: 3.50

Explanation / Answer

Please find my implementation.

public class Student {

  

   private String studentID;

   private String lastName;

   private String firstName;

   private double gpa;

   private String phoneNumber;

  

   private static int countStudents;

   private static double totalGpa;

   private static double averageGpa;

  

   public Student(String studentID, String lastName, String firstName, double gpa, String phoneNumber) {

       this.studentID = studentID;

       this.lastName = lastName;

       this.firstName = firstName;

       this.gpa = gpa;

       this.phoneNumber = phoneNumber;

      

       countStudents++;

       totalGpa += gpa;

       averageGpa = totalGpa/countStudents;

      

       printStudentRecord();

   }

   public String getStudentID() {

       return studentID;

   }

   public String getLastName() {

       return lastName;

   }

   public String getFirstName() {

       return firstName;

   }

   public double getGpa() {

       return gpa;

   }

   public String getPhoneNumber() {

       return phoneNumber;

   }

   public void setStudentID(String studentID) {

       this.studentID = studentID;

   }

   public void setLastName(String lastName) {

       this.lastName = lastName;

   }

   public void setFirstName(String firstName) {

       this.firstName = firstName;

   }

   public void setGpa(double gpa) {

       this.gpa = gpa;

   }

   public void setPhoneNumber(String phoneNumber) {

       this.phoneNumber = phoneNumber;

   }

  

   @Override

   public String toString() {

       return "Student id: "+studentID+", "+

               "Last Name: "+lastName+", "+

               "First Name: "+firstName+", "+

               "GPA: "+String.format("%.2f", gpa)+", "+

               "Phone Number: "+phoneNumber+" "+

               "Current Student Count: "+countStudents+", "+

               "Total GPA: "+String.format("%.2f", totalGpa)+", "+

               "Average GPA: "+String.format("%.2f", totalGpa)+" ";

              

   }

  

   public void printStudentRecord(){

       System.out.println(toString());

   }

}

#########

import java.util.Scanner;

public class StudentTest {

  

   public static void main(String[] args) {

      

       Scanner sc = new Scanner(System.in);

      

       System.out.println("Please enter tudent id, last name, first name, gpa, and phone number>");

       String line = sc.nextLine();

      

       String strArr[] = line.split("\s+");

      

       Student s = new Student(strArr[0], strArr[1], strArr[2],

               Double.parseDouble(strArr[3].trim()), strArr[4]);

      

       sc.close();

      

   }

}

/*

Sample run:

Please enter tudent id, last name, first name, gpa, and phone number>

1 Doe Jhon 3.0 111-4325

Student id: 1, Last Name: Doe, First Name: Jhon, GPA: 3.00, Phone Number: 111-4325

Current Student Count: 1, Total GPA: 3.00, Average GPA: 3.00

*/