Exercise 4: Java
Instructions:
• The deadline of the submission is ONE week after the exercise is given.
• Please read and understand the following Java classes and answer the questions:
o TwoDShape class (Super Class)
▪ Variables: name
▪ Methods : constructors, accessor and mutator methods, toString() (overridden
method) and calcArea() (abstract method)
o Circle class (Sub Class)
▪ Variables: diameter
▪ Methods : necessary methods
o Rectangle class (Sub Class)
▪ Variables: width and length
▪ Methods : necessary methods
Write a Java program to store 5 objects regardless of its type into an array and do the
following tasks:
a) Display the information of each object (if any)
b) Display the radius of each Circle object (if any)
c) Calculate and display the average of area for Rectangle objects only (if any)
d) Display the information of the object that has the smallest value of area (if any)
For this exercise, students should use the array [ ] and the following statements (do not
read the value from users).
listShp[0] = new Circle(“Circle A”, 1.5f);
listShp[1] = new Rectangle(“Rectangle A”, 2.0f, 4.0f);
listShp[2] = new Rectangle(“Rectangle B”, 2.5f, 6.0f);
listShp[3] = new Circle(“Circle B”, 3.0f);
listShp[4] = new Circle(“Circle C”, 2.0f);
• Please write down your student ID, Name and Class Group on the first page of your file.
• Save the source code and the output in the PDF format and submit the file after the
Google Classroom’s link is given.
• PLEASE DO NOT ARCHIVE THE FILES.
NOTE:
Please do it by yourself without using any assisting tool app for e.g.
ChatGPT