import java.util.Scanner;
public class testcircle {
public static void main(String[] args) {
System.out.println("welcome");
double i;
Scanner sc = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
String choice = y;
while (i<=10) {
while (choice.equalsIgnoreCase("y"));
{
System.out.println("Enter the Radius");
String radius=sc.next();
System.out.println("Enter the Object name");
String Object = scan.next();
if(Object.equalsIgnoreCase("circle"))
{
circle CircleShapeRef[i] = new circle();
CircleShapeRef[i].setradius(radius);
System.out.println("The Circle Object");
System.out.println(CircleShapeRef[i].getDisplayText());
System.out.println(CircleShapeRef[i].area());
i++;
}
else if(Object.equalsIgnoreCase("sphere"))
{
sphere CircleShapeRef[i] = new sphere();
CircleShapeRef[i].setradius(radius);
System.out.println("The Sphere Object");
System.out.println(CircleShapeRef[i].getDisplayText());
System.out.println(CircleShapeRef[i].area());
i++;
}
else {
System.out.println("Object not valid");
}
}
} }
}
I created a CircleShape super class, and made circle to inherit CircleShape, then inherited sphere class from circle
Now the user should choose upto 10 objects b/w circle and sphere and find the area.
I used CircleShapeRef to store the objects. Is my syntax correct?
These are the errors I am getting when I executed:
javac testcircle.java
testcircle.java:18: ']' expected
circle CircleShapeRef = new circle();
^
testcircle.java:18: illegal start of expression
circle CircleShapeRef = new circle();
^
testcircle.java:28: ']' expected
sphere CircleShapeRef = new sphere();
^
testcircle.java:28: illegal start of expression
sphere CircleShapeRef = new sphere();
^
4 errors