Question: I'm having trouble getting a Java program to compile properly. Can someone tell me what is wrong and how to fix it? When I try
I'm having trouble getting a Java program to compile properly. Can someone tell me what is wrong and how to fix it? When I try to run TestGeometricThing, I get an error message I have never seen before. Here are the files I am working with:
GeometricThing.java
public abstract class GeometricThing {
private String color = "white"; private boolean filled; private java.util.Date dateCreated;
/** Construct a default geometric object */ protected GeometricThing() { dateCreated = new java.util.Date(); }
/** Construct a geometric object with color and filled value */ protected GeometricThing(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; }
/** Return color */ public String getColor() { return color; }
/** Set a new color */ public void setColor(String color) { this.color = color; }
/** Return filled. Since filled is boolean, * the get method is named isFilled */ public boolean isFilled() { return filled; }
/** Set a new filled */ public void setFilled(boolean filled) { this.filled = filled; }
/** Get dateCreated */ public java.util.Date getDateCreated() { return dateCreated; }
@Override public String toString() { return "created on " + dateCreated + " color: " + color + " and filled: " + filled; }
/** Abstract method getArea */ public abstract double getArea();
/** Abstract method getPerimeter */ public abstract double getPerimeter();
}
Square.java
public class Square extends GeometricThing{
double side = 1.0; ////default value of 1.0
Square(double side){
this.side=side;//specific side } @Override public double getArea() {
return side*side; //returns area of square }
@Override public double getPerimeter() {
return 4*side; //returns peremeter of square } public double getSide() { return side; //returns length of side }
public String toString(){
return "side of sqare is "+side; //display side }
}
Rectangle.java
public class Rectangle extends GeometricThing {
private double width; private double height;
public Rectangle() { }
public Rectangle(double width, double height) { this.width = width; this.height = height; }
/** Return width */ public double getWidth() { return width; }
/** Set a new width */ public void setWidth(double width) { this.width = width; }
/** Return height */ public double getHeight() { return height; }
/** Set a new height */ public void setHeight(double height) { this.height = height; }
@Override /** Return area */ public double getArea() { return width * height; }
@Override /** Return perimeter */ public double getPerimeter() { return 2 * (width + height); } }
Circle.java
public class Circle extends GeometricThing {
private double radius;
public Circle() { }
public Circle(double radius) { super("red", false); this.radius = radius; }
/** Return radius */ public double getRadius() { return radius; }
/** Set a new radius */ public void setRadius(double radius) { this.radius = radius; }
@Override /** Return area */ public double getArea() { return radius * radius * Math.PI; }
/** Return diameter */ public double getDiameter() { return 2 * radius; }
@Override /** Return perimeter */ public double getPerimeter() { return 2 * radius * Math.PI; }
/* Print the circle info */ public void printCircle() { System.out.println("The circle is created " + getDateCreated() + " and the radius is " + radius); }
}
TestGeometricThing.java
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; public class TestGeometricThing { static double sumOfArea = 0; static List
System.out.println("The two objects have the same area? " + equalArea(geoThing1, geoThing2));
System.out.println("Circle"); displayGeometricThing(geoThing1);
System.out.println("Rectangle"); displayGeometricThing(geoThing2);
System.out.println("Square"); displayGeometricThing(geoThing3);
System.out.println("Do circle and rectangle have same area? " + equalArea(geoThing1, geoThing3));
list.add(geoThing1); list.add(geoThing2); list.add(geoThing3);
double sum = sumArea(list); System.out.println("Sum of area: " + sum);
GeometricThing obj = findBiggestThing(list); System.out.println("Biggest area of thing is: " + obj.getArea()); } public static boolean equalArea(GeometricThing object1,GeometricThing object2) { return object1.getArea() == object2.getArea(); }
public static void displayGeometricThing(GeometricThing object) { System.out.println("The area is " + object.getArea()); System.out.println("The perimeter is " + object.getPerimeter()); System.out.println(); } public static double sumArea(List
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
