Any help for java final review hw A schools is described by a name. For full cre
ID: 3842714 • Letter: A
Question
Any help for java final review hw
A schools is described by a name.
For full credit, follow good principles of class design and encapsulation.
Question 1
Write the class header for the School class.
Question 2
Declare the instance data variables for the School class. A School is described by a name.
Question 3
Write two constructors:
a default constructor sets the name of the school to the empty String
a second constructor sets the name based on parameters
Question 4
Write a toString method that outputs "Name: " followed by the name of the school.
Question 5
Write appropriate getters and settters.
**In the next set of questions, write a complete class called PrivateSchool. The PrivateSchool class is a child class of the School class.
A private school is described by the name and the tuition.
Question 1
Write the class header for the PrivateSchool class.
Question 2
Declare the instance data variables for the PrivateSchool class.
A PrivateSchool is described by a name and tuition.
Question 3
Write a constructor that sets the name and tuition based on parameters
Question 4
Write a toString method that outputs "Name: " followed by the name and then then "Tuition: " followed by tuition. (You do not need to format the output of the tuition value.)
Question 5
Write appropriate getters and settters. Include validity checks when appropriate.
Question 6
Write an equals method for the PrivateSchool class.
Two private school objects are logically equivalent if they have the same name (ignoring capitalization) and the same tuition.
Question 7
Have the PrivateSchool class implement the Comparable interface.
PrivateSchool objects are ordered first by name and then by tuition (smallest to largest).
Write the new class header and the complete compareTo method.
Explanation / Answer
1.
public class Student
{
}
2.
public class Student
{
private String name;
}
3.
public class Student
{
private String name;
Student()
{
name = "";
}
Student(String name)
{
this.name = name;
}
}
4.
public class Student
{
private String name;
Student()
{
name = "";
}
Student(String name)
{
this.name = name;
}
@override
public String toString()
{
return "Name: " + name;
}
}
5.
public class Student
{
private String name;
Student()
{
name = "";
}
Student(String name)
{
this.name = name;
}
@override
public String toString()
{
return "Name: " + name;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
Next Set:
1.
public class Student
{
private String name;
Student()
{
name = "";
}
Student(String name)
{
this.name = name;
}
@override
public String toString()
{
return "Name: " + name;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
public class PrivateSchool extends Student
{
}
2.
public class Student
{
private String name;
Student()
{
name = "";
}
Student(String name)
{
this.name = name;
}
@override
public String toString()
{
return "Name: " + name;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
public class PrivateSchool extends Student
{
private double tuition;
}
3.
public class Student
{
private String name;
Student()
{
name = "";
}
Student(String name)
{
this.name = name;
}
@override
public String toString()
{
return "Name: " + name;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
public class PrivateSchool extends Student
{
private double tuition;
PrivateSchool(String name, double fee)
{
super(name);
this.tuition = fee;
}
}
4.
public class Student
{
private String name;
Student()
{
name = "";
}
Student(String name)
{
this.name = name;
}
@override
public String toString()
{
return "Name: " + name;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
public class PrivateSchool extends Student
{
private double tuition;
PrivateSchool(String name, double fee)
{
super(name);
this.tuition = fee;
}
@override
public String toString()
{
return super.toString() + " Tuition: " + tuition;
}
}
5.
public class Student
{
private String name;
public Student()
{
name = "";
}
public Student(String name)
{
this.name = name;
}
@override
public String toString()
{
return "Name: " + name;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
public class PrivateSchool extends Student
{
private double tuition;
public PrivateSchool(String name, double fee)
{
super(name);
this.tuition = fee;
}
@override
public String toString()
{
return super.toString() + " Tuition: " + tuition;
}
public double getTuition()
{
return tuition;
}
public void setTuition(double fee)
{
if(fee > 0)
tuition = fee;
}
}
6.
public class Student
{
private String name;
public Student()
{
name = "";
}
public Student(String name)
{
this.name = name;
}
@override
public String toString()
{
return "Name: " + name;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
public class PrivateSchool extends Student
{
private double tuition;
public PrivateSchool(String name, double fee)
{
super(name);
this.tuition = fee;
}
@override
public String toString()
{
return super.toString() + " Tuition: " + tuition;
}
public double getTuition()
{
return tuition;
}
public void setTuition(double fee)
{
if(fee > 0)
tuition = fee;
}
public boolean equals(Object obj) {
if (obj instanceof PrivateSchool)
return name.equalsIgnoreCase((PrivateSchool)obj.getName()) && tuition == (PrivateSchool)obj.getTuition();
else
return false;
}
}
7.
public class Student
{
private String name;
public Student()
{
name = "";
}
public Student(String name)
{
this.name = name;
}
@override
public String toString()
{
return "Name: " + name;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
public class PrivateSchool extends Student implements Comparable<PrivateSchool>
{
private double tuition;
public PrivateSchool(String name, double fee)
{
super(name);
this.tuition = fee;
}
@override
public String toString()
{
return super.toString() + " Tuition: " + tuition;
}
public double getTuition()
{
return tuition;
}
public void setTuition(double fee)
{
if(fee > 0)
tuition = fee;
}
public boolean equals(Object obj) {
if (obj instanceof PrivateSchool)
return name.equalsIgnoreCase((PrivateSchool)obj.getName()) && tuition == (PrivateSchool)obj.getTuition();
else
return false;
}
public int compareTo(PrivateSchool ps)
{
return toString().compareTo(ps.toString());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.