CS 1073 Introductory Programming
for Scientific Applications Homework 5: Circle Class in Java
Due Date:
Wednesday, 17 November 2004, at start of class.
The Circle class: Overview:
Create a Circle
class similar to the Rectangle
class that we studied.
A Circle class: Details
Create a Circle
class similar to the Rectangle
class that we studied. Use the version on the right side,
with a separate class, call it
CircleMain,
holding the main
function. Here are details:
Include two private int
data fields, call them xCenter
and yCenter
for the x and y coordinates of the center of the circle.
Include one private int
data field, call it radius
for the radius of the circle.
Add public
accessor methods (functions)
getXCenter(),
getYCenter(),
and getRadius()
to return the values of these fields.
Add public
methods (functions) which each return a
double:
namely circum() and
area()
that will calculate and return the circumference and the area,
respectively, of the circle.
Add three constructors (these are always
public, and always
named Circle:
One with no parameters that creates a circle at the
origin, with radius 0.
One with a single parameter that creates a circle at
the origin with radius the parameter value.
One with three parameters that creates a circle with
radius the first parameter values, and with center the
next two parameter values.
Add a toString
method that prints the center and radius of the circle.
In the separate
CircleMain class,
write code to test out this
Circle class,
similar to the previous
Rectangle class.
In particular you should print the different values of
the circles created below, using the
toString method
as well as printing them individually.
Create an instance of
Circle
using the constructor with no parameters.
Name it c1.
Create an instance c2
that uses the constructor with one parameter. Use a
3 for its radius.
Create an instance c3
that uses the constructor with three parameters. Use a
2 for its radius, and 3 and 4 for the x and y coordinate of its center.