Write a Java class that represents a Student with instance variables * name, * i
ID: 3636026 • Letter: W
Question
Write a Java class that represents a Student with instance variables* name,
* id,
* an array of courses(integers) which holds the grade for each course(40 courses total).
* numberOf CoursesTaken
Include the following methods for your class:
* constructor that accepts (name, id) then initialize name, Id, number of courses and
array. Note that we are not receiving any values for the array or NumberOfCourses
taken but we still need to initialize our array.
* calculateOverallGpa(): reads the array of grades and then calculate the GPA and return
it
* addCourse(int grade) : accepts one grade and place it in the appropriate location of the
array of grades
* isOhonered(): return true if GPA >=3.7, otherwise return false
* isGraduating(): return true if total courses taken by the student >35, otherwise return
false
* toString() : Calling the toString method should genereate the following output:
Name : Mary Lu
ID: 1234567
Total courses taken : 37
Overall GPA: 4.0
Mary is an honored student
Here is the list of Mary’s grade:
100, 100, 100, 100,….
You are not allowed to add any other methods or variable to this class.
NOTE: notice that the instance variable numberOfcoursesTaken must be updated in one of the
above methods; it is your job to find out the method that is appropriate. You need this
instance variable to calculate the GPA.
Explanation / Answer
//Program 1: Student .java public class Student { private String name; private int id; private int courses[]; private int numberOfCoursesTaken; private final int MAX_NO_OF_COURCES=40; public double calculateOverallGpa(){ double gpa=0d; int total = 0; for(int i=0;i35){ is = true; } return is; } public String toString(){ StringBuffer sb = new StringBuffer(); sb.append("Name : "); sb.append(this.name); sb.append(" "); sb.append("ID : "); sb.append(this.id); sb.append(" "); sb.append("Total courses taken : "); sb.append(this.numberOfCoursesTaken); sb.append(" "); sb.append("Overall GPA : "); sb.append(calculateOverallGpa()); sb.append(" "); sb.append(" "); if(isOhonered()){ sb.append("Mary is an honored student Here is the list of Mary’s grade : "); for(int i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.