Simple Java Program. It is about classes . All you have to do is fill in the stu
ID: 3532761 • Letter: S
Question
Simple Java Program. It is about classes. All you have to do is fill in the stubs and requirements in each java file, it will be obvious once you open the site and get them into a writer or notepad. The java files can be found on these two websites. The driver file is the MakingCircles.java. Please copy paste the code when you're done.If you look at the notation for Lab9 Circle, it tells you above each method what it wants you to make the method do. So write the methods and then test them with the driver he has provided. Hope this helps. Thank you!
http://people.bridgewater.edu/~vcapacci/Classes/2013-Sp-CSCI200/Labs/Lab9/MakingCircles.java
http://people.bridgewater.edu/~vcapacci/Classes/2013-Sp-CSCI200/Labs/Lab9/Circle.java
Explanation / Answer
/********************************************
Circle is a class representing circle-like
shapes.
@author Vincent Capaccio
@version V1 04/04/2013
*******************************************/
public class Circle
{
// Circles are defined by their radius
private double radius;
/****************************************
Constructor Builds a Circle of radius
inRadius. If the radius is negative, sets
it to 1.
@param inRadius The radius of this Circle
*****************************************/
public Circle(double inRadius)
{
radius = inRadius;
if (inRadius < 0) //invalid data
radius = 1;
}
/*****************************************
getRadius is an accessor method which
returns the radius of this Circle
@return radius of this Circle
*****************************************/
public double getRadius()
{
return radius;
}
/****************************************
getCircumference is an accessor method
which calculates and returns the circumference
of this circle: cirumference = PI * d where d
is the diameter.
@return The diameter of this Circle object
*****************************************/
public double getCircumference()
{
// YOUR CODE GOES HERE
return 2 * Math.PI * radius;
}
/*****************************************
getAreaCircle calculates and returns the
area of this Circle object using the formula
area = PI * <sup>2</sup>
@return the area of this Circle
*****************************************/
public double getArea()
{
// YOUR CODE GOES HERE
return Math.PI * radius * radius;
}
/*****************************************
toString provides a representation of this
Circle. Your String should read:
A circle of radius, XXXXXX, and area, YYYYY.
XXXXXX is replaced by the radius and YYYYY
is replaced by the area.
@return String representation of this Circle
*****************************************/
public String toString()
{
// YOUR CODE GOES HERE
return "A circle of radius, " + radius +
", and area, " + getArea();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.