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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!