In this lab we will practice interface inheritance.
Start with the Shape
interface and associated files that we studied in class
and do the following:
Square
that implements Shape
. Make all the necessary variables and methods for this class.main
to test your implementation
of Square
. You may add it in the Square
class or add another class UseSquare
with
a main
.UseShape
to add at least one instance
of Square
to places where an instance
of Circle
is used.UseShape
that sums the areas of all
the geometric objects in an array passed in as an argument. The
method signature is as follows:
public static double sumArea(Shape[] a);You will need to modify the
Shape
interface and other classes to implement this method.
UseShape
that creates an array of 7
objects (2 circles, 2 rectangles, and 3 squares) and computes
their total area using the sumArea
method that you just
defined, and prints the result to the console.Start with the sorting_objects_2/Selection.java
in Lecture
19 and do the following:
Account
with two
attributes: name
for account owner's name
and balance
for account balance. This class is not much
different than the Account
class that we have used
before.toString
, equals
, compareTo
,
etc. See sorting_objects_2/Point.java
in Lecture 19 as
an example.main
of Selection
to create an array
of at least 5 Account
objects this time instead of an
array of Point
objects.ssort
given
in Selection.java
, much like the Point
array was
sorted. Print the array before and after sorting and make sure
your account is sorted correctly. You may choose to sort the
array by account owner's name or by account balance. Your
call!search
given
in Selection.java
, much like the Point
array was
used to do a search.isort
)
this time to sort an array of objects in Selection.java
.
This method should be capable of sorting an array of any objects
as long as it implements the Comparable
interface, much
like the ssort
method in Selection.java
.
Although the file name is Selection.java
, we will add an
insertion sort method there as well. If that bothers you, rename
the file to something that is more appropriate such
as Sort.java
isort
to sort the Account
array this
time. Print the array before and after sorting as we did with
selection sort.Make sure that your program works correctly. If you have difficulties, please get help during the lab and also outside the lab if you did not finish it in the lab.
When you are done with these, feel free to leave the lab.