Description
·Source code: Generics.
In this assignment, you should submit three Java files for Question 1 and2:ArrayExample.java,ArrayExa andArrayListExample.java. For Question 3 the “difficult question”, you should submit a folder that contains all modified files.
These questions use a hierarchy of classes of simple geometric objects:
·GeometricShape.java
·TwoDShape.java
·ThreeDShape.java
·Circle.java
·Cone.java
·Rectangle.java
·Sphere.java
Test.javais a little test class that you can run to make sure the other classes are working.
1. Java Arrays and Type Compatibility Rules
Look at the skeleton for the main method inArrayExample.java. Add some additional statements to it so that the code compiles correctly, and when it is run, it raises
a java.lang.ArrayStoreException when adding a cone to geoshapes (Adding a circle should be
OK). Here is the exception you should get:
Assignment https://eclass.srv.ualberta.ca/mod/assign/view.php?id=3237749
the supersize_list method. Uncomment them (but don’t otherwise change them). You should get the following additional output:
super-sizing a list of rectangles
Rectangle[width=4.0, height=6.0]
Rectangle[width=10.0, height=10.0]
Total number of shapes: 2
super-sizing a list of spheres
Sphere[radius=20.0]
Sphere[radius=100.0]
Sphere[radius=0.0]
Total number of shapes: 3
Hint: starts with generalizing the GeometricShape :
public interface GeometricShape<T extends GeometricShape<T>> {
public voiddescribe();
public T supersize();
}
Generics.zip