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

Write a class encapsulating the concept of a Student, assuming that a student ha

ID: 3743663 • Letter: W

Question

Write a class encapsulating the concept of a Student, assuming that a student has the following attributes: last name, first name, id, array of grades. Include a constructor, the accessors and mutators, and method toString. Also code the following methods: one returning the GPA using the array of grades (assuming each grade represents a course grade and all courses have the same number of credit hours) and a method to add a course grade to the array of grades (this means creating a larger array). Write a client class to create 2 student objects and test all your methods. java

Explanation / Answer

public class Student { private String firstName, lastName; private int id; private double[] grades; public Student() { grades = new double[0]; } public Student(String firstName, String lastName, int id) { this(); this.firstName = firstName; this.lastName = lastName; this.id = id; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public int getId() { return id; } public void setId(int id) { this.id = id; } public double[] getGrades() { return grades; } public void setGrades(double[] grades) { this.grades = grades; } @Override public String toString() { String result = "Name = " + firstName + " " + lastName + " "; result += "Id = " + id + " "; result += "Grades = "; for(int i = 0; i
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