I\'m having trouble getting a Java program to compile properly. Can someone tell
ID: 3818119 • Letter: I
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 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<GeometricThing> list = new ArrayList<GeometricThing>();
public static void main(String[] args) {
GeometricThing geoThing1 = new Circle(5);
GeometricThing geoThing2 = new Rectangle(5, 3);
GeometricThing geoThing3 = new Square(5);
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<GeometricThing> list){
for(int i=0;i<list.size();i++){
sumOfArea+=list.get(i).getArea();
}
return sumOfArea;
}
public static GeometricThing findBiggestThing(List<GeometricThing> list){
List list1 = new ArrayList();
for(int i=0;i<list.size();i++){
list1.add(list.get(i).getArea());
}
GeometricThing obj = (GeometricThing)Collections.max(list1);
return obj;
}
}
Explanation / Answer
.ORIG x3000
LD R3, POSASC ;Loads R3 with #48
LD R4, NEGASC
LD R1, word ;R1 = word
Include R6, R6, #5 ;Length of word
GETC ;Gets the burn
OUT ;Prints the burn
Include R2, R2, R0 ;Stores the burn in R2
;Include R2, R2, R4 ;To ascii
What's more, R0, R0, #0 ;set R0 back to 0
Circle
Furthermore, R5, R2, R1 ;check if singe is equivalent
Include R1, R1, #1 ;augmentation to next singe in word
Include R6, R6, #-1
BRnp LOOP
Include R0, R0, R5 ;Set R0 to # of events
OUT ;Print # of events
End
POSASC .FILL x0030 ;#48
word .STRINGZ "hi" ;word to tally events of a roast
NEGASC .FILL xFFD0 ;#-48
.END
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.