Results 1 to 11 of 11
  1. #1
    Dai
    Dai is offline Member
    Join Date
    Sep 2013
    Posts
    15
    Rep Power
    0

    Default Need feedback with my code, thank you

    Hello everyone, so I need help with the code I am working on for my assignment, below is what it's been asking me to do and then you can see the code, I'm still getting some error, any feed back as the output should be something like "Bike is in gear 5 with a cadence of 20 and travelling at a speed of 10.
    The MountainBike has a Dual suspension." and then something similar for DownhillMountainBike and I just cant get it right. Thank you in advance.

    Extend the MountainBike class to create another class called DownhillMountainBike. Downhill bikes are a specialised type of mountain bike with a very strong frame, much stronger than a typical mountain bike. Create the DownhillMountainBike class with getFrameStrength(), setFrameStrength(int strength), and printDescription() methods. The frame strength is to be a value in between 1 and 10, inclusive. Test the DownhillMountainBike class using the TestBikes class from the same web link provided above.

    Java Code:
    public class MountainBike {
    	private String suspension;
    
        public MountainBike(
                   int startCadence,
                   int startSpeed,
                   int startGear,
                   String suspensionType){
            super();
            this.setSuspension(suspensionType);
        }
    
        public String getSuspension(){
          return this.suspension;
        }
    
        public void setSuspension(String suspensionType) {
            this.suspension = suspensionType;
        }
    
        public void printDescription() {
        	
            System.out.println("The " + "MountainBike has a" +
                getSuspension() + " suspension.");
            
        }
    	
    		
    	}
    Java Code:
    public class DownhillMountainBike extends MountainBike {
    
    	 private int strengthWidth = 10;
    	private String speed;
    	private String cadence;
    
    	public DownhillMountainBike(
    			 int startCadence,
                 int startSpeed,
                 int startGear,
                 String strengthType){
          super(startCadence,
                  startSpeed,
                  startGear, strengthType);
          this.setFrameStrength(strengthType);
    		
    	}
    	 private void setFrameStrength(Object strengthType) {
    		
    		
    	}
    	public int getFrameStrength (){
    	      return this.strengthWidth;
    	    }
    
    	    public void setFrameStrength(int strength) {
    	        this.strengthWidth = strength;
    	    }
    	public void printDescription() {
    		System.out.println(""\nMountainBike is" + "in gear " + this.gear"
    	            + " with a cadence of " + this.cadence +
    	            " and travelling at a speed of " + this.speed + ". ");
    		
    	}
    
    	public static void main(String[] args){
    	   MountainBike bike01;
    	   DownhillMountainBike bike02;
    
    	   
    	    bike01 = new MountainBike(20, 10, 5, "Dual");
    	    bike02= new DownhillMountainBike (20,10, 4, "strength");
    
    	    ((MountainBike) bike01).printDescription();
    	    bike02.printDescription();
    	  
    	  
    	  }
    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Need feedback with my code, thank you

    Java Code:
    System.out.println(""\nMountainBike is" + "in gear " + this.gear"
                    + " with a cadence of " + this.cadence +
                    " and travelling at a speed of " + this.speed + ". ");
    See how the syntax highlighting isn't working correctly. Why do you think that is?

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Need feedback with my code, thank you

    Java Code:
    "Why " + "do " + "you " + "do " + "this"
    "instead of doing this?"

  4. #4
    Dai
    Dai is offline Member
    Join Date
    Sep 2013
    Posts
    15
    Rep Power
    0

    Default Re: Need feedback with my code, thank you

    even if I fix the marks still giving me an error as it show "The MountainBike has astrength suspension.
    MountainBike isin gearnull with a cadence of null and travelling at a speed of null" when it should print "Bike is in gear 5 with a cadence of 20 and travelling at a speed of 10.
    The MountainBike has a Dual suspension."

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Need feedback with my code, thank you

    Well it prints MountainBike and not Bike because that is what you tell it to print in the toString method.
    It prints null because you are not assigning any values to gear, cadence and speed. The DownhillMountainBike passes those values to the super constructor but the MountainBike constructor does nothing with them.

    Pretend you are the computer and trace through your code "executing" (write stuff down on paper) each line of code. That way you will see what is and isn't being done.

  6. #6
    Dai
    Dai is offline Member
    Join Date
    Sep 2013
    Posts
    15
    Rep Power
    0

    Default Re: Need feedback with my code, thank you

    Alright so I have been working on this codes and now I have no error, but I can't print anything for DownhillMountainBike class, keeps telling me that there is an error in line 39, I removed and then I get errors, I'm super lost at this point! thank you

    Java Code:
    public class MountainBike {
    	private int suspension;
    	private String cadence;
    	private int gear;
    	private String speed;
    
        public MountainBike(
                   int startCadence,
                   int startSpeed,
                   int startGear,
                   int gear2){
            super();
            this.setSuspension(gear2);
        }
    
        public MountainBike(int startCadence, int startSpeed, int startGear,
    			String string) {
    		
    	}
    
    	public int getSuspension(){
          return this.suspension;
        }
    
        public void setSuspension(int gear2) {
            this.suspension = gear2;
        }
    
        public void printDescription() {
        	System.out.println("The " + "MountainBike has a" +
                getSuspension() + "  dual suspension.");
            
    	
        }
    
    	public String getCadence() {
    		return cadence;
    	}
    
    	public void setCadence(String cadence) {
    		this.cadence = cadence;
    	}
    
    	public int getGear() {
    		return gear;
    	}
    
    	public void setGear(int gear) {
    		this.gear = gear;
    	}
    
    	public String getSpeed() {
    		return speed;
    	}
    
    	public void setSpeed(String speed) {
    		this.speed = speed;
    	}
    	}


    Java Code:
    public class DownhillMountainBike extends MountainBike {
    
    	private int strengthWidth = 4;
    	private int speed = 15;
    	private int cadence =20;
    	private static int gear = 6;
    	private static DownhillMountainBike bike02;
    
    	public DownhillMountainBike(
    			 int startCadence,
                 int startSpeed,
                 int startGear,
                 int string){
    		super(startCadence,
    	              startSpeed,
    	              startGear, gear);
    	      this.setFrameStrength(string);
    		
    	} 
    	
    		public int getFrameStrength (){
    	      return this.strengthWidth;
    	    }
    
    	    public void setFrameStrength(int string) {
    	        this.strengthWidth = string;
    	    }
    	public void printDescription() {
    		System.out.println("The DonwhillMountainBike" + "has" + gear+ "and"+ cadence +" at the"+ speed+ "full suspention");
    		
    	}
    
    	public static void main(String[] args){
    	  MountainBike bike01; 
    	   bike01 = new MountainBike(20, 10, 5, "Dual");
    	 
    	    ((MountainBike) bike01).printDescription();
    	    ((DownhillMountainBike) bike02).printDescription();
    	     }
    
    }

  7. #7
    Dai
    Dai is offline Member
    Join Date
    Sep 2013
    Posts
    15
    Rep Power
    0

    Default Re: Need feedback with my code, thank you

    sorry line 38

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Need feedback with my code, thank you

    When you get an error you need to copy and paste the exact error message. Where is the variable bike02 declared?

  9. #9
    Dai
    Dai is offline Member
    Join Date
    Sep 2013
    Posts
    15
    Rep Power
    0

    Default Re: Need feedback with my code, thank you

    if I declared bike02 it gives me an error too!
    Java Code:
     DownhillMountainBike bike02;

  10. #10
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Need feedback with my code, thank you

    We don't read minds. We have no friggin clue what your error is unless you tell us.

  11. #11
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,357
    Rep Power
    6

    Default Re: Need feedback with my code, thank you

    Exactly, who has the crystal ball this week anyway? Pass it to Junky.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. UML feedback
    By behedwin in forum New To Java
    Replies: 0
    Last Post: 10-05-2012, 12:21 PM
  2. Feedback
    By GrumpyBum in forum Suggestions & Feedback
    Replies: 0
    Last Post: 04-25-2012, 12:34 PM
  3. Feedback on my PrimeNumber Finder code please.
    By fatabass in forum New To Java
    Replies: 4
    Last Post: 12-22-2011, 11:43 PM
  4. Calculator Feedback
    By 0026sd in forum New To Java
    Replies: 0
    Last Post: 09-20-2011, 03:23 PM
  5. Need feedback for my program.
    By Pojahn_M in forum New To Java
    Replies: 3
    Last Post: 08-12-2011, 09:12 PM

Tags for this Thread

Posting Permissions

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