Hey Everyone,
I am taking my first java class right now(although I am not new to coding, I've taken many c and C++ classes). I am working on an assignment and I have run into some trouble. The assignment is to create an abstract class that has a bunch of extended classes(main class shape with extended classes such as circle, rectangle, etc...). I have created the classes I believe and I was creating a demo program to test/debug it and i have run into a error i can't seem to figure out.
Below is my main Shape class, my extended Circle class, and my ShapeDemo program.
Main Shape class
~~~~~~~~~~~~~~
package CS249Mazur; public abstract class Shape { public double Area; public double Perimeter; public Shape() { Area = this.getArea(); Perimeter = this.getPerimeter(); } public Shape(Shape original) { Area = original.Area; Perimeter = original.Perimeter; } public String toString() { return ("Area = "+this.Area+"\nPerimeter = "+this.Perimeter); } public boolean equals(Shape otherShape) { return (this.Area == otherShape.Area); } public int compareTo(Shape otherShape) { if (this.Area < otherShape.Area) return -1; else if(this.Area > otherShape.Area) return 1; else return 0; } public abstract double getArea(); public abstract double getPerimeter(); }
Extended Circle class
~~~~~~~~~~~~~~~~~~
package CS249Mazur; public abstract class Circle extends Shape { public double radius; public Circle(double theRadius) { super(); if(theRadius > 0) radius = theRadius; else { System.out.println("Fatal Error: Illegal Radius amount entered."); System.exit(0); } } public Circle(Circle original) { super(original); radius = original.radius; } public double getArea() { return 3.141592*radius*radius; } public double getPerimeter() { return 2-3.141592*radius; } public double getRadius() { return this.radius; } public void setRadius(double r) { this.radius = r; } public String toString() { return (super.toString()+"\nRadius = "+this.radius); } }
Shape Demo program
~~~~~~~~~~~~~~~~~
package CS249Mazur; public abstract class ShapeDemo { Shape array[]; double rad=0; //ask user for shape //figure out what shape they entered is //Based on what they entered ask for the parts needed rad=5; Circle o1; array[0]=o1; o1.setRadius(rad); //move to next spot in the array //and get the next shape to enter into the array }
The demo program is not what I will be using for the actual program just something simple to test if my classes worked. I am getting an error on the line where i create the double rad. some kind of syntax error. saying: Syntax error on token ";", { expected after this token.
Any and all help would be appreciated!
Thanks!