Results 1 to 5 of 5
  1. #1
    DesertFlower is offline Member
    Join Date
    Oct 2012
    Posts
    7
    Rep Power
    0

    Default Getting error, "class, interface or enum expected", not sure why.

    Compiler is telling me there is a "class, interface, or enum expected" on line 68, but this likely means it's on a previous line. I can't find it. Please help. New to Java-please forgive terrible code. C/P from jGrasp. Also, can someone tell me how I indicate the new dispatch in line 28 to save in a short term memory location? I can't find this in the tutorials. Can I just save it somewhere on my PC?

    Java Code:
    import becker.robots.*;
    import java.util.Vector;
    
    public class SuperShuttle extends RobotGB implements Driver
    {
        Dispatcher      dispatcher      = null;
        
        public SuperShuttle(CityGB city, int street, int avenue, Direction direction, Dispatcher dispatcher)
        {
            super(city,street,avenue,direction);
            this.dispatcher = dispatcher;
        }
    
        public void driveTaxi() 
        {
    		//The following "for" statement provides iteration much like the while.
    		//The dispatcher object will provide you a Dispatch. 
    		//See the Dispatcher method list on how to retrieve the next dispatch.
    		//Hint: You will need to declare a short-term memory location to store that dispatch.		
    		drive(dispatcher.get(i).getStreet(),dispatcher.get(i).getAvenue());
    		  for(int i=0;i<dispatcher.size();i++) 
    		  {
    		  drive();
    		  transportPassenger();
    		  }
    		  }
    		//get next dispatch
    	public Dispatch get(int i)
        {
            return list.get(i);
        }     
    		  //method for drive
    	public void drive()
    	{
    		  	if(getStreet<destinationStreet())
    			{
    			Direction.EAST();
    			}
    			else
    			{
    			Direction.West();
    			}
    			while(getStreet!=destinationStreet())
    			{
    			move();
    			}
    			if(getAvenue<destinationAvenue())
    			{
    			Direction.SOUTH();
    			}
    			else
    			{
    			Direction.NORTH();
    			}
    			while(getAvenue!=destinationAvenue())
    			{
    			move();
    			}
    			}
    			//method for transportPassenger
    	public void transportPassenger()
    			{
    			Traveler newTraveler = pickupTraveler(); 
    			drive(newTraveler.getDestinationAvenue(),newTraveler.getDestinationStreet());
    		 	dropOffTraveler();	
    			}		
        }
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default Re: Getting error, "class, interface or enum expected", not sure why.

    Check your curly brackets.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Getting error, "class, interface or enum expected", not sure why.

    Java-please forgive terrible code. C/P from jGrasp.
    We'll forgive you, but your compiler won't! There's something screwy with the braces. Format the code properly and check that he braces line up.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,235
    Rep Power
    19

    Default Re: Getting error, "class, interface or enum expected", not sure why.

    Make that indentation consistent* and check for mismatched braces.

    * Code Conventions for the Java Programming Language: Contents

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    DesertFlower is offline Member
    Join Date
    Oct 2012
    Posts
    7
    Rep Power
    0

    Default Re: Getting error, "class, interface or enum expected", not sure why.

    Quote Originally Posted by DarrylBurke View Post
    Make that indentation consistent* and check for mismatched braces.

    * Code Conventions for the Java Programming Language: Contents

    db
    Thank you for that link! I will check it over tomorrow and indent better. That should help me find the problem. :)

Similar Threads

  1. Replies: 1
    Last Post: 10-03-2012, 09:38 PM
  2. Replies: 4
    Last Post: 10-20-2011, 05:10 AM
  3. class interface or enum expected Imports java.io.*; error
    By prathamkool in forum New To Java
    Replies: 2
    Last Post: 10-02-2011, 04:53 PM
  4. Replies: 2
    Last Post: 10-02-2010, 02:13 AM
  5. Replies: 3
    Last Post: 12-05-2008, 08:34 PM

Posting Permissions

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