0% found this document useful (0 votes)
13 views1 page

Java Exercise: Shape Classes Implementation

The exercise requires students to work with Java classes, specifically a super class TwoDShape and its subclasses Circle and Rectangle. Students must create an array to store five shape objects, display their information, calculate the average area of rectangles, and identify the shape with the smallest area. Submissions must include student details and be formatted as a PDF, with a strict prohibition against using assisting tools.

Uploaded by

mynamejeff
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

Java Exercise: Shape Classes Implementation

The exercise requires students to work with Java classes, specifically a super class TwoDShape and its subclasses Circle and Rectangle. Students must create an array to store five shape objects, display their information, calculate the average area of rectangles, and identify the shape with the smallest area. Submissions must include student details and be formatted as a PDF, with a strict prohibition against using assisting tools.

Uploaded by

mynamejeff
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like