You are on page 1of 2

Object Oriented Programming Essentials

Tutorial 8 – Introduction to Object Oriented Programming

 Create a folder called Tutorial 8 to save all files.

Rectangle

- length: int
- width: int

+ Rectangle (length: int, width: int)


+ area (): int
+ perimeter (): int
+ printDimensions(): void
+ setLength (ln: int): void
+ setWidth (w: int): void

Circle

- diameter: double

+ Circle ()
+ setDiameter(d:double): void
+ getDiameter (): double
+ findArea (): double
+ findCircumference (): double
Download & store the class files (Rectangle.class & Circle.class) in the Tutorial 8 folder.

1. Write a program called CreateShapes that does the following:

a) Creates a Rectangle object called r1 with dimensions length:10,

width:4.

b) Print the area and perimeter of r1.

c) Change the length of r1 to 15 and the width to 7;

d) Print the dimensions of r1, and the new area and perimeter.

e) Create a Circle object called c1 that has a diameter of 12.

f) Print the area and circumference of c1. (Be sure the answers are not zero)

g) Print the radius of Circle c1.

h) Allow a user to enter the diameter of another circle and create the

corresponding Circle object called c2.

i) Create the relevant objects for the following and print the total area and total

perimeter of the shapes.

i. Rectangle: length:10, width:4

ii. Circle: diameter 20

iii. Rectangle: length:18, width:15

iv. Circle: radius 6

You might also like