DailyDoseOf
DailyDoseOf

Reputation: 23

Switch statement client problems

The error occurs where i posted commented *'s, first error on the i in switch it is saying i need ;, second error on the first case is saying it is orphaned. i am very confused i would like an explanation of what is happening if possible.

public class Shape3D_Client{
  public static final int MAX = 6;
  public static void main (String [] args){

    Shape3D[] shapes = new Shape3D[MAX];
    shapes[0] = new SquarePyramid(37,20);
    shapes[1] = new Sphere(20);
    shapes[2] = new RetangularPrism(10, 20, 37);
    shapes[3] = new Cube(10);
    shapes[4] = new Cylinder(10, 20);
    shapes[5] = new CircularCone(10, 20);

    for(int i = 0; i < shapes.length; i++){
      System.out.println("\nThis is a ");
      Switch (i){//*********************************
        case 0://***********************************
           System.out.println("square pyramid. ");
          break;
        case 1:
          System.out.println("Sphere. ");
          break;
        case 2:
          System.out.println("RetangularPrism. ");
          break;
        case 3:
          System.out.println("Cube. ");
          break;
        case 4:
          System.out.println("Cylinder. ");
          break;
        case 5:
          System.out.println("CircularCone. ");
          break;
      }//closes switch
       System.out.printf("Area = %.2f", shapes[i].getArea());
       System.out.printf(". Volume = %.2f\n", shapes[i].getVolume());
       System.out.println("Output calling the method printInfo - polymorphism at work!");
      printInfo(shapes[i]);
      System.out.println("----------------------------------------------------     ------------------------------------");
    }//closes for loop

  }//closes main

  public static void printInfo(Shape3D s) {
    System.out.println(s);
    System.out.printf("Area = %.2f", s.getArea());
    System.out.printf(". Volume = %.2f\n", s.getVolume());
  }//closes method
}//closes class

Upvotes: 1

Views: 26

Answers (1)

Rahul Tripathi
Rahul Tripathi

Reputation: 172608

Java is case sensitive. You need to use

switch(i)

instead of

Switch(i)

Upvotes: 1

Related Questions