Class TestCircle will not compile, but that should be because of problems in the other files. Unless there is a typo, this is from the lesson plan.
import java.text.DecimalFormat;
public class TestCircle
{
public static void main(String[] args)
{
DecimalFormat showTwoDecimals = new DecimalFormat( "0.00" );
Circle c1 = new Circle(2.5, 22, 44);
double newRadius = 6.0;
System.out.println("This shape is a " + c1.getName() +
"\nlocated at " + c1.getLocation() +
"\nRadius is " + c1.getRadius());
System.out.println("The shape area is: "
+ showTwoDecimals.format(c1.area())+"\n");
System.out.println("The shape perimiter (circumference) is: " +
showTwoDecimals.format(c1.perimeter())+"\n");
System.out.println("After changing the radius to " + newRadius);
c1.setRadius(newRadius);
System.out.println(", it is a "+ c1 + "nArea is "
+ showTwoDecimals.format(c1.area())+"\n");
System.out.println("The shape perimiter (circumference) is: " +
showTwoDecimals.format(c1.perimeter())+"\n");
}
}
Circle class will not compile, these are the errors:
.\Point.java:6: Shape(java.lang.String) in Shape cannot be applied to ()
{
^
.\Point.java:12: Shape(java.lang.String) in Shape cannot be applied to ()
{
^
public abstract class Circle extends Point implements Shape2D
{
protected double radius;
public Circle()
{
setRadius( 0 );
}
public Circle( double circleRadius, int x, int y)
{
this.radius=circleRadius;
}
// Get radius of Circle
public double getRadius()
{
return radius;
}
// Set radius of Circle
public void setRadius(double r)
{
radius = ( r >= 0 ? r : 0 );
}
// Calculate area of Circle
public double area()
{
return Math.PI * radius * radius;
}
// convert the Circle to a String
public String toString()
{
return "Circle with center at (" + x + ", " + y + ")" +
" and radius = " + radius;
}
// return the class name
public String getName()
{
return "Circle";
}
// return the center location
public String getLocation()
{
return "X = " + x + ", Y = " + y;
}
}
Point Class will not compile, the two errors are (the same as the circle class):
.\Point.java:6: Shape(java.lang.String) in Shape cannot be applied to ()
{
^
.\Point.java:12: Shape(java.lang.String) in Shape cannot be applied to ()
{
^
public abstract class Point extends Shape
{
protected int x, y;
public Point()
{
this.x = 0;
this.y = 0;
}
public Point( int xCoordinate, int yCoordinate )
{
this.x = xCoordinate;
this.y = yCoordinate;
}
}
Shape Class (Will Compile)
public abstract class Shape
{
public String name;
public Shape(String shapeName)
{
this.name = shapeName;
}
public abstract String getName();
public abstract String getLocation();
}
Shape2D interface (Will Compile)
public interface Shape2D
{
public double getArea();
public double getPerimiter();
}

New Topic/Question
Reply




MultiQuote




|