Java Reference
In-Depth Information
The following test code should then output the area of the
Circle
and
Rectangle
objects:
public static void
main(String[] args)
{
Circle c =
new
Circle(4);
// Radius of 4
Rectangle r =
new
Rectangle(4,3);
// Height
=
4, Width
=
3
ShowArea(c);
ShowArea(r);
}
public static void
ShowArea(Shape s)
{
double
area = s.area();
System.out.println("The area of the shape is " + area);
}
11. Create a
Student
class that has instance variables for the student's last name and
ID number, along with appropriate constructors, accessors, and mutators. Make the
Student
class implement the
Comparable
interface. Define the
compareTo
method
to order
Student
objects based on the student ID number. In the
main
method,
create an array of at least five
Student
objects, sort them using
Arrays.sort
, and
output the students. They should be listed by ascending student number. Next,
modify the
compareTo
method so it orders
Student
objects based on the lexico-
graphic ordering of their last name. Without modification to the
main
method, the
program should now output the students ordered by name.
VideoNote
Solution to
Programming
Project 13.11