[go: up one dir, main page]

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

CSBP219

This document provides instructions for an object-oriented programming exercise to create a Circle class with attributes like radius and color, and methods to calculate area. It also provides instructions to create a CircleTester class to test the functionality of the Circle class by constructing Circle objects with different parameters and calling their methods. The tasks involve adding constructors, accessor and mutator methods, and a toString method to the Circle class, and modifying the test class accordingly.

Uploaded by

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

CSBP219

This document provides instructions for an object-oriented programming exercise to create a Circle class with attributes like radius and color, and methods to calculate area. It also provides instructions to create a CircleTester class to test the functionality of the Circle class by constructing Circle objects with different parameters and calling their methods. The tasks involve adding constructors, accessor and mutator methods, and a toString method to the Circle class, and modifying the test class accordingly.

Uploaded by

maryam mukhtar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

O bj ect Or ient ed Pr o gr a m m ing ( CS BP219)

Fall 2023
In-Class Task 01

Name: …………………………………………..….. ID: ……………………....

Exercise 1 – Circle.java & CircleTester.java (Use Netbeans)


A) Create a class “Circle” with the following:
1. Declare two private instance variables, not accessible from outside this class
a. radius (double) and color (String)
2. Create a default constructor with no argument
a. radius (default value 1.0) and color (default value “red”)
3. Create a second constructor which takes one double parameter for radius
4. Create an accessor method getRadius() to return the radius of the Circle
5. Create a method calcArea() to calculate and returns the area of the Circle

B) Create a class “CircleTester” to test the functionality of Circle calss


1. Declare an instance of Circle class called c1. Construct the instance c1 by calling the "default"
constructor
2. Call the public methods to display the radius and area of c1
Smaple Output: The circle c1 has radius of 1.0 and area of 3.14159265358
3. Declare an instance of class circle called c2. Construct the instance c2 by calling the initializing
constructor and passing the value 2.0 for the radius
4. Call the public methods to display the radius and area of c2
Smaple Output: The circle c2 has radius of 2.0 and area of 12.5663706143

C) Modify class “Circle” as follows:


1. Create a third constructor which takes two arguments - a double for radius and a String for color
2. Add an accessor method (getter) for variable color to retrieve the color

D) Modify the test program as follows:


1. Declare an instance of Circle class called c3. Construct the instance c3 by calling the third constructor
and passing the values 2.5 for radius and “green” for color
2. Call the public methods to display the radius, color and area of c3

E) Modify class “Circle” as follows:


1. Create mutator methods (setters) for radius and color

F) Modify the test program as follows:


1. Declare an instance of Circle class called c4. Construct the instance c4 by calling the default
constructor
2. Change the radius of c4 to 5.0
3. Change the color of c4 to “black”
4. Print the radius and color of c4

G) Modify class “Circle” as follows:


1. Create a toString() method to return a string of this instance in the form of Circle[radius = ?, color = ?]

H) Modify the test program as follows:


1. Declare an instance of Circle class called c5. Construct the instance c5 by calling the second
constructor and passing the value 3.7 for the radius
2. Call toString() to return a description of the instance

1/1

You might also like