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

Exer 17

Download as doc, pdf, or txt
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 1

College of Computer Studies

Laboratory Activity Form

Course Number CPE262


Course Title OOP2
Class definition, toString(), equals(Object obj),
Topics Covered:
Composition, Inheritance

Design and implement classes in Java using composition and


Objectives:
inheritance.

Description

Use the MyPoint class for this activity.

1) The Circle Class


 Implement a class called Circle for representing a circle. The circle has two
data members, a MyPoint object representing the center of the circle and a
double value representing the radius.
 Include appropriate constructors for your Circle class and the necessary
getter and setter methods.
 Also include methods for finding the area and circumference of the circle.
area = pi * radius * radius and circumference = 2 * pi * radius.
(You may use the static constant pi in the Math class)
 Override the toString method of the Object class
 Override the equals method of the Object class. Two circle objects are equal
if they have the same center and the same radius.
 Write a simple main method that creates Circle objects and tests each of the
methods that you have defined.

2) After you have completed the Circle Class, implement a class called Cylinder that
extends the Circle class.

 A cylinder has one additional data member for representing the height (type
double).
 Create appropriate constructors for your Cylinder class
 Include the necessary getters and setter for your additional attributes
 Include methods for finding the volume and area of your Cylinder.
area = 2 * (area of the circle in this cylinder) +
2 * pi * radius + height
volume = (area of the circle in this cylinder) * height
 Override the toString method of the Object class. Try to use the toString of
the Circle class and then just concatenate the remaining values
 Override the equals method of the Object class. Two Cylinder objects are
equal if they have the same center and the same radius and the same height.
 Write a simple main method that creates Cylinder objects and tests each of
the methods that you have defined.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy