Results 1 to 3 of 3

Thread: Why won't this compile?

Threaded View

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Resolved Why won't this compile?

    Compiler keeps complaining about <identifier> expected at 1st in the enum GearState.
    Code:
    class Transmission{
      public enum GearState{neutral,1st,2nd,3rd,4th,5th,6th};
      private int currentgear = GearState.neutral;
    
      public void setGear(GearState gs){
        currentgear = gs;
      }
      public GearState getNextGear(){
      switch(currentgear){
       case neutral: return GearState.neutral;
       case 1st: return GearState.1st;
       case 2nd: return GearState.2nd;
       case 3th: return GearState.3rd;
       case 4th: return GearState.4th;
       case 5th: return GearState.5th;
       case 6th return GearState.6th;
      }
     }
      public void printGears(){
       for(GearState gs: GearState.values()){
        System.out.println(gs);
       }
      }
     }
     public class Car {
      public static void main(String[] args){
       Transmission trans = new Transmission();
       System.out.println(trans.getNextGear());
       trans.setGear(Transmission.GearState.1st);
       System.out.println(trans.getNextGear());
      }
     }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width