Question

In Java: Requirements: 1. Create a class called Bike. 2. Create these private attributes: int currentSpeed...

In Java:

Requirements:

1. Create a class called Bike.

2. Create these private attributes:

  • int currentSpeed
  • int currentGear
  • String paintColor

3. Create a constructor that takes 2 arguments: speed, gear, color.

4. Create another constructor that takes no arguments.

5. Create a method called goFaster(int amount) which increases the speed by the given amount.

6. Create a method called brake() which sets the speed to 0.

7. Create a method called print() which describes the bike and the speed it is going.

8. Create another class RoadBike that extends Bike.

9. RoadBike has an attribute of int seatHeight.

10. Create a constructor that takes speed, gear, color, heightOfSeat and creates a RoadBike.

11. Create a method called print() which describes the bike. This method should call the Bike print method and then print heightOfSeat.

12. Create a class called Test with static main that does the following:

  • Bike myFirstBike = new Bike();
  • myFristBike.print();
  • RoadBike myRoadBike= RoadBike(3,5,"blue", 25);
  • myRoadBike.goFaster(5);
  • myRoadBike.brake();
  • myRoadBike.goFaster(7);
  • myRoadBike.goFaster(2);
  • myRoadBike.print();
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

Please find the code below and output attached.


class Bike
{

private int currentSpeed;
private int currentGear;
private String paintColor;
  
Bike()
{
currentGear = currentSpeed = 0;
paintColor = "";
}
  
Bike(int CS, int CG,String PC)
{
currentSpeed = CS;
currentGear = CG;
paintColor = PC;
}
  
void goFaster(int amount)
{
currentSpeed = currentSpeed + amount;
}
  
void brake()
{
currentSpeed =0;
}
  
void print()
{
System.out.println("Current speed: "+currentSpeed+" currentGear: "+currentGear+"paintColor: "+paintColor);
}

}
class RoadBike extends Bike
{
private int seatHeight;
RoadBike(int CS,int CG,String PC,int SH)
{

super(CS,CG,PC);
seatHeight = SH;
}
@Override
void print()
{
super.print();
System.out.println("Height of Bike Seat:"+seatHeight);
}
  
}
public class Test
{
   public static void main(String[] args)
   {
       Bike myFirstBike = new Bike();
myFirstBike.print();
  
RoadBike myRoadBike = new RoadBike(3,5,"blue", 25);
myRoadBike.print();
myRoadBike.goFaster(5);
myRoadBike.print();
myRoadBike.brake();
myRoadBike.print();
myRoadBike.goFaster(7);
myRoadBike.print();
myRoadBike.goFaster(2);
myRoadBike.print();

   }
}

output:

Thanks,

kindly upvote.

Add a comment
Know the answer?
Add Answer to:
In Java: Requirements: 1. Create a class called Bike. 2. Create these private attributes: int currentSpeed...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python code? 1. Create a class called Person that has 4 attributes, the name, the age,...

    python code? 1. Create a class called Person that has 4 attributes, the name, the age, the weight and the height [5 points] 2. Write 3 methods for this class with the following specifications. a. A constructor for the class which initializes the attributes [2.5 points] b. Displays information about the Person (attributes) [2.5 points] c. Takes a parameter Xage and returns true if the age of the person is older than Xage, false otherwise [5 points] 3. Create another...

  • In Java please, Create a class called airConditioner which has 3 private attributes; integer temperature, boolean...

    In Java please, Create a class called airConditioner which has 3 private attributes; integer temperature, boolean on and String location and has 5 behaviors: turning the air conditioner on and off (called turnON and turnOFF with no return and no arguments) checking to see if the air conditioner is on (called isON wihch returns boolean) sets the temperature( setTemp which receives an int argument) and gets current temp (getTemp) which accepts no value and returns the int temp

  • Create a java class for an object called Student which contains the following private attributes: a...

    Create a java class for an object called Student which contains the following private attributes: a given name (String), a surname (family name) (String), a student ID number (an 8 digit number, String or int) which does not begin with 0. There should be a constructor that accepts two name parameters (given and family names) and an overloaded constructor accepting two name parameters and a student number. The constructor taking two parameters should assign a random number of 8 digits....

  • Create a class House with the private fields: numberOfUnits of the type int, yearBuilt of the...

    Create a class House with the private fields: numberOfUnits of the type int, yearBuilt of the type int, assessedPrice of the type double. A constructor for this class should have three arguments for initializing these fields. Add accessors and mutators for all fields except a mutator for yearBuilt, and the method toString. Create a class StreetHouse which extends House and has additional fields: streetNumber of the type int, homeowner of the type String, and two neighbors: leftNeighbor and rightNeighbor, both...

  • In Java Create a class Worker. Your Worker class should include the following attributes as String...

    In Java Create a class Worker. Your Worker class should include the following attributes as String variables: Name, Worker ID, Worker Address, Worker City, Worker State Create the constructor that initializes the above worker attributes. Then make another class name HourlyWorker that inherits from the Worker class.   HourlyWOrker has to use the inherited parent class variables and add in hourlySalary and billableHours. Your HourlyWorker class should contain a constructor that calls the constructor from the Worker class to initialize the...

  • In Python Programming: Write a class named Car that has the following data attributes: _ _year_model...

    In Python Programming: Write a class named Car that has the following data attributes: _ _year_model (for the car’s year model) _ _make (for the make of the car) _ _speed (for the car’s current speed) The Car class should have an _ _init_ _ method that accepts the car’s year model and make as arguments. These values should be assigned to the object’s _ _year_model and _ _make data attributes. It should also assign 0 to the _ _speed...

  • The Java class called Holiday is started below. An object of class Holiday represents a holiday...

    The Java class called Holiday is started below. An object of class Holiday represents a holiday during the year. This class has three instance variables: name, which is a String representing the name of the holiday day, which is an int representing the day of the month of the holiday month, which is a String representing the month the holiday is in public class Holiday { private String name; private int day; private String month; // your code goes here...

  • Write a Java class that implements the concept of Coins, assuming the following attributes (variables): number...

    Write a Java class that implements the concept of Coins, assuming the following attributes (variables): number of quarters, number of dimes, number of nickels, and number of pennies. Include two constructors (non-argument constructor that assigns 1 to each coin, and another constructor that takes necessary arguments to create an object), needed getter and setter methods, method toString (to print coins objects in a meaningful way), and method equals (to compare two coins objects based on number of coins). Also include...

  • In Java Create an interface called Amount that includes a method called setPrice (). Create an a...

    In Java Create an interface called Amount that includes a method called setPrice (). Create an abstract class named Book that inherits from the interface Amount. Include a String field for the book’s title and a double field for the book’s Price . Within the class, include a constructor that requires the book title and add two getter methods — one that returns the title and one that returns the price. Include an abstract method named setPrice (). Create a...

  • Design and implement class Circle to represent a circle object. The class defines the following attributes...

    Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: 1.      A private variable of type double named radius to represent the radius. Set to 1. 2.      Constructor Methods: •        Python : An overloaded constructor method to create a default circle. •        C# & Java: Default Constructor with no arguments. •        C# & Java: Constructor method that creates a circle with user-specified radius. 3.      Method getRadius() that returns the radius. 4.     ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT