Question
Given the following class definition: public class Student { private String name; private String major; private double gpa; private int hours; public Student(String newName, String
Given the following class definition:
public class Student {
private String name;
private String major;
private double gpa;
private int hours;
public Student(String newName, String newMajor, double newGpa, int newHours) {
name = newName;
major = newMajor;
gpa = newGpa;
hours = newHours;
}
public String toString() {
// Type your code here **********
}
}
Assume that studentAmy is an Student object with the following attributes:
name is "Amy Farrell"; major is "History"; gpa is 3.87 and hours is 14. (These are all given and stored in the studentAmy object)
The following statement is trying to print the object:
System.out.println(studentAmy);
Write the toString method so that the output of object will display all information of Amy. The output will also add one of the following comment:
1. if the gpa >= 3.5 - " You are an excellent student!"
2. if the gpa >= 2.0 - "You are making your grades just fine."
3. otherwise - Woops! Need a little more effort!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started