Results 1 to 6 of 6
  1. #1
    teekei is offline Member
    Join Date
    May 2011
    Posts
    39
    Rep Power
    0

    Default Unaware as to how the code did not compile??? confused?

    This is my only class that didn't compile w/o bugs. I can't figure out why.

    Java Code:
    public class Bus extends MotorVehicles
    {
    	private int nbrPassSeats;
    	private int range;
    	private int stowCapacity;
    
    	public Bus(int wheels, String trans, String brakes, String steering, int passSeats, int distance, int stowage)
    	{
    		super(wheels, trans, brakes, steering);
    		setNbrPassSeats(passSeats);
    		setRange(distance);
    		setStowCapacity(stowage);
    	}
    
    	public void setNbrPassSeats(int passSeats)
    	{
    		nbrPassSeats = passSeats;
    	}
    
    	public int NbrPassSeats()
    	{
    		return nbrPassSeats;
    	}
    
    	public void setRange(int distance)
    	{
    		range = distance;
    	}
    
    	public int getRange()
    	{
    		return range;
    	}
    
    	public void setStowCapacity(int stowage)
    	{
    		stowCapacity = stowage;
    	}
    
    	public int getStowCapacity()
    	{
    		return stowCapacity;
    	}
    
    	@Override
    	public String toString()
    	{
    		return String.format( "\nThis vehicle has %d wheels, %s transmission, %s brakes, %s steering, %d seats, a range of %d miles, and a cargo capacity of %d pounds\n",
    		getNbrWheels(), getTranType(), getBrakeSystem(), getSteeringSystem(), getNbrPassSeats(),
    		getRange(), getStowCapacity() );
    	}
    
    }
    Java Code:
    symbol: class MotorVehicles
    public class Bus extends MotorVehicles
                             ^
    C:\Users\Timzareli\Documents\JCreator LE\MyProjects\TestMyVehicles\src\Bus.java:57: cannot find symbol
    symbol  : method getNbrWheels()
    location: class Bus
    		getNbrWheels(), getTranType(), getBrakeSystem(), getSteeringSystem(), getNbrPassSeats(),
    		^
    C:\Users\Timzareli\Documents\JCreator LE\MyProjects\TestMyVehicles\src\Bus.java:57: cannot find symbol
    symbol  : method getTranType()
    location: class Bus
    		getNbrWheels(), getTranType(), getBrakeSystem(), getSteeringSystem(), getNbrPassSeats(),
    		                ^
    C:\Users\Timzareli\Documents\JCreator LE\MyProjects\TestMyVehicles\src\Bus.java:57: cannot find symbol
    symbol  : method getBrakeSystem()
    location: class Bus
    		getNbrWheels(), getTranType(), getBrakeSystem(), getSteeringSystem(), getNbrPassSeats(),
    		                               ^
    C:\Users\Timzareli\Documents\JCreator LE\MyProjects\TestMyVehicles\src\Bus.java:57: cannot find symbol
    symbol  : method getSteeringSystem()
    location: class Bus
    		getNbrWheels(), getTranType(), getBrakeSystem(), getSteeringSystem(), getNbrPassSeats(),
    		                                                 ^
    C:\Users\Timzareli\Documents\JCreator LE\MyProjects\TestMyVehicles\src\Bus.java:57: cannot find symbol
    symbol  : method getNbrPassSeats()
    location: class Bus
    		getNbrWheels(), getTranType(), getBrakeSystem(), getSteeringSystem(), getNbrPassSeats(),
    		                                                                      ^
    C:\Users\Timzareli\Documents\JCreator LE\MyProjects\TestMyVehicles\src\Bus.java:53: method does not override or implement a method from a supertype
    	@Override
    	^
    7 errors
    
    Process completed.
    Here is my application and my other classes.

    Java Code:
    public class TestMyVehicles
    {
    	public static void main(String [] args)
    	{
    //		MotorVehicle[] myVehicles = new MotorVehicle[4]; // comment this line to test your code
    		MotorVehicle[] myVehicles = new MotorVehicle[6]; // uncomment this line to test your code
    
    		myVehicles[0] = new MotorVehicle( 4, "auto","anti-lock", "power" );
    		myVehicles[1] = new MotorVehicle( 6, "automatic", "disc", "power assist");
    		myVehicles[2] = new Automobile(4, "automatic", "anti-lock", "power assist", 4, 4);
    		myVehicles[3] = new Automobile(4, "automatic", "anti-lock", "power assist", 5, 5);
    		myVehicles[4] = new Bus( 14, "automatic", "disc", "power assist", 40, 300, 2200);
    		myVehicles[5] = new Bus( 18, "automatic", "disc", "power assist", 60, 450, 4200);
    
    		for (MotorVehicle currVehicle : myVehicles)
    				System.out.printf( currVehicle.toString());
    	}
    
    
    }  	 // end class TestMyVehicles
    Java Code:
    symbol  : class Bus
    location: class TestMyVehicles
    		myVehicles[5] = new Bus( 18, "automatic", "disc", "power assist", 60, 450, 4200);
    		                    ^
    2 errors
    
    Process completed.
    Java Code:
    public class Automobile extends MotorVehicle
    {
       private int nbrDoors;
       private int nbrWindows;
    
       // Four-argument constructor
       public Automobile( int wheels, String trans, String brakes, String steering,
       					  int doors, int windows)
       {
       	  super (wheels, trans, brakes, steering);
          setNbrDoors( doors );
          setNbrWindows( windows );
    
       } // end Automobile constructor
    
    
       // set number of doors
       public void setNbrDoors( int doors )
       {
          nbrDoors = doors;
       } // end method setFirstName
    
    
       // return nubmer of doors
       public int getNbrDoors()
       {
          return nbrDoors;
       } // end method getNbrDoors
    
    
       // set number of windows
       public void setNbrWindows( int windows )
       {
          nbrWindows = windows;
       } // end method setNbrWindows
    
    
       // return nubmer of windows
       public int getNbrWindows()
       {
          return nbrWindows;
       } // end method getNbrWindows
    
    
    
       // return String representation of MotorVehicle object
       @Override
       public String toString()
       {
          return String.format( "\nThis vehicle has %d wheels, %s transmission, %s brakes, %s steering, %d doors and %d windows",
          	getNbrWheels(), getTranType(), getBrakeSystem(), getSteeringSystem(),
          		getNbrDoors(), getNbrWindows() );
       } // end method toString
    
    
    }  	 // end class Automobile
    Java Code:
    //public abstract class MotorVehicle
    public class MotorVehicle
    {
       private int nbrWheels;
       private String tranType;
       private String brakeSystem;
       private String steeringSystem;
    
       // Four-argument constructor
       public MotorVehicle( int wheels, String trans, String brakes, String steering)
       {
          setNbrWheels( wheels);
          setTranType( trans );
          setBrakeSystem( brakes );
          setSteeringSystem( steering);
    
       } // end four-argument Employee constructor
    
    
       // set number of wheels
       public void setNbrWheels( int wheels )
       {
          nbrWheels = wheels; // should validate
       } // end method setFirstName
    
    
       // return nubmer of wheels
       public int getNbrWheels()
       {
          return nbrWheels;
       } // end method getNbrWheels
    
    
       // set transmission type
       public void setTranType( String trans )
       {
          if ((trans == "automatic") || (trans == "standard"))
          	tranType = trans;
          else
          	tranType = "standard";
       } // end method setTranType
    
    
       // return TranType
       public String getTranType()
       {
          return tranType;
       } // end method getLastName
    
    
       // set type of brake system
       public void setBrakeSystem( String brakes )
       {
          brakeSystem = brakes;
       } // end method setBrakeSystem
    
    
       // return type of brake system
       public String getBrakeSystem()
       {
          return brakeSystem;
       } // end method
    
       // set type of steering system
       public void setSteeringSystem( String steering )
       {
          steeringSystem = steering;
       } // end method setSteeringSystem
    
    
       // return type of steering system
       public String getSteeringSystem()
       {
          return steeringSystem;
       } // end method
    
    
       // return String representation of MotorVehicle object
       @Override
       public String toString()
       {
          return String.format( "\nThis vehicle has %d wheels, %s transmission, %s brakes, and %s steering",
          	getNbrWheels(), getTranType(), getBrakeSystem(), getSteeringSystem() );
       } // end method toString
    
    
    }  	 // end abstract class MotorVehicle
    I apologize for the amount of code, any help given will be greatly appreciated.

    Thank you

  2. #2
    JDScoot is offline Member
    Join Date
    Jun 2011
    Location
    San Diego, CA
    Posts
    24
    Rep Power
    0

    Default

    It looks to me in your Bus class, the getNbrPassSeats() method is missing the "get" part. you call getNbrPassSeats() at the bottom but the actual method name you have right now is NbrPassSeats() w/o the "get".

  3. #3
    teekei is offline Member
    Join Date
    May 2011
    Posts
    39
    Rep Power
    0

    Default

    I have done that, thank you, now I only have 6 errors, do you know why my class is not inheriting the methods while my other classes successfully did so?

  4. #4
    teekei is offline Member
    Join Date
    May 2011
    Posts
    39
    Rep Power
    0

    Default

    I also am wondering why I have an override error, I don't see anything wrong with how I declared it.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,873
    Rep Power
    25

    Default

    The first part of the error message that you posted appears to be missing some text. I think that missing part is the key to the rest of the problems.

  6. #6
    teekei is offline Member
    Join Date
    May 2011
    Posts
    39
    Rep Power
    0

Similar Threads

  1. Replies: 3
    Last Post: 04-19-2011, 12:33 AM
  2. Code does not Compile
    By ustar in forum New To Java
    Replies: 13
    Last Post: 03-06-2010, 05:54 PM
  3. Replies: 6
    Last Post: 11-12-2009, 11:50 AM
  4. Code will not compile
    By ShotGunRockets in forum New To Java
    Replies: 17
    Last Post: 05-10-2009, 04:31 AM
  5. confused code
    By creativehacker in forum New To Java
    Replies: 6
    Last Post: 07-02-2007, 09:10 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
  •