Ch 9: 9.5

getClass().getName() + "[name=" + name + ",gpa=" + gpa + "]"
Record your participation in Piazza clicker question Lesson17 Q1
Download overriding_project.zip. Modify the Product class to implement toString. You can use the example from the previous slide as a model. Run the tester. Verify your output looks like the Expected.
In the substring method of a subclass
return super.toString() + "[major=" + major + "]";
Record your participation in Piazza clicker question Lesson17 Q2
Now modify Painting to implement toString. Call super.toString() and then add the artist instance variable. You can use the example from the previous slide as a model. Uncomment the next two statements and run the tester again. Verify your output looks like the Expected.
Record your participation in Piazza clicker question Lesson17 Q3
What happens when you execute this statement? Try it and see.
System.out.println(System.out);
Why?
Record your participation in Piazza clicker question Lesson17 Q4
What will happen when you try to compile and run this code
Object college = "SJSU"; System.out.println(college.length());
public boolean equals(Object otherObject)
If we are providing an equals method for a Student class with a name and gpa,
Student other = (Student)otherObject;
public boolean equals(Object otherObject)
{
Student other = (Student)otherObject;
return (this.name.equals(other.name))
&& (this.gpa == other.gpa);
}
Record your participation in Piazza clicker question Lesson17 Q5
Record your participation in Piazza clicker question Lesson17 Q6
Record your participation in Piazza clicker question Lesson17 Q7
if (otherObject == null) {return false;} //solves problem 3
if (this.getClass() != otherObject.getClass()) {return false;}//solves problems 1 and 2
public boolean equals (Object otherObject)
{
if (!super.equals(otherObject))
{
return false; //the objects are not equal
}
CollegeStudent other = (CollegeStudent)otherObject;
return this.major.equals(other.major);
}
Record your participation in Piazza clicker question Lesson17 Q8