Question

Design MountainBike and RoadBike class for a simulation game Mike is a programmer working in his ...

Design MountainBike and RoadBike class for a simulation game

Mike is a programmer working in his afterhours to design games for mobile platforms. His recent

project is a simulation game in which a player controls a bike to move across a variety of simulated

environments. To start coding, Mike has to design a collection of bikes including a mountain bike

and a road bike, so that the player can choose the preferred bike. He is now implementing two

classes, MountainBike and RoadBike, to simulate the behavior of the bikes.

In MountainBike, Mike is going to implement the fields and methods:

MountainBike

+cadence: double //pedalling rate (per minute)

+gear:int

+speed:double

+suspension:string // type of the suspension

MountainBike() //a constructer

+setCadence:void

+setGear:void

+setSpeed:void

+setSuspension:void

+brake():void // method to apply brake to reduce speed

+accelerate():void //method to accelerate the bike

+toString:string //print a snapshot of the current condition of the bike

In RoadBike, Mike is going to implement the following fields and methods:

RoadBike

+cadence: double //pedalling rate (per minute)

+gear:int

+speed:double

+tire:string // type of the tires

RoadBike() //a constructer

+setCadence:void

+setGear:void

+setSpeed:void

+setTire:void

+brake():void // method to apply brake to reduce speed

+accelerate():void //method to accelerate the bike

+toString:string //print a snapshot of the current condition of the bike

Page 2

Could you help Mike to design both classes?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java code for the given requirement:

MountainBike class:

public class MountainBike {
  
   //instance variables
   public double cadence;
   public int gear;
   public double speed;
   public String suspension;
  
   //a constructor
   public MountainBike(double cadence, int gear, double speed, String suspension) {
       super();
       this.cadence = cadence;
       this.gear = gear;
       this.speed = speed;
       this.suspension = suspension;
   }

   //methods
   public void setCadence(double cadence) {
       this.cadence = cadence;
   }

   public void setGear(int gear) {
       this.gear = gear;
   }

   public void setSpeed(double speed) {
       this.speed = speed;
   }

   public void setSuspension(String suspension) {
       this.suspension = suspension;
   }
  
   public void brake(){
       //reduce the speed to 0
       this.speed = 0;
   }
   public void accelerate(){
      
   }

   @Override
   public String toString() {
       return "MountainBike [cadence=" + cadence + ", gear=" + gear + ", speed=" + speed + ", suspension=" + suspension
               + "]";
   }
  
}

RoadBike class:

public class RoadBike {

   //instance variables
   public double cadence;
   public int gear;
   public double speed;
   public String tire;
  
   //a constructor
   public RoadBike(double cadence, int gear, double speed, String tire) {
       super();
       this.cadence = cadence;
       this.gear = gear;
       this.speed = speed;
       this.tire = tire;
   }

   //methods
   public void setCadence(double cadence) {
       this.cadence = cadence;
   }

   public void setGear(int gear) {
       this.gear = gear;
   }

   public void setSpeed(double speed) {
       this.speed = speed;
   }

   public void setTire(String tire) {
       this.tire = tire;
   }
  
   public void brake(){
       //reduce the speed to 0
       this.speed = 0;
   }
   public void accelerate(){
      
   }

   @Override
   public String toString() {
       return "RoadBike [cadence=" + cadence + ", gear=" + gear + ", speed=" + speed + ", tire=" + tire + "]";
   }
  
}

Add a comment
Know the answer?
Add Answer to:
Design MountainBike and RoadBike class for a simulation game Mike is a programmer working in his ...
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
  • Design MountainBike and RoadBike class for a simulation game Mike is a programmer working in his...

    Design MountainBike and RoadBike class for a simulation game Mike is a programmer working in his afterhours to design games for mobile platforms. His recent project is a simulation game in which a player controls a bike to move across a variety of simulated environments. To start coding, Mike has to design a collection of bikes including a mountain bike and a road bike, so that the player can choose the preferred bike. He is now implementing two classes, MountainBike...

  • Tic Tac Toe Game: Help, please. Design and implement a console based Tic Tac Toe game....

    Tic Tac Toe Game: Help, please. Design and implement a console based Tic Tac Toe game. The objective of this project is to demonstrate your understanding of various programming concepts including Object Oriented Programming (OOP) and design. Tic Tac Toe is a two player game. In your implementation one opponent will be a human player and the other a computer player. ? The game is played on a 3 x 3 game board. ? The first player is known as...

  • Please write the program in python: 3. Design and implement a simulation of the game of...

    Please write the program in python: 3. Design and implement a simulation of the game of volleyball. Normal volleyball is played like racquetball, in that a team can only score points when it is serving. Games are played to 15, but must be won by at least two points. 7. Craps is a dice game played at many casinos. A player rolls a pair of normal six-sided dice. If the initial roll is 2, 3, or 12, the player loses....

  • JAVA Problem:  Coffee    Design and implement a program that manages coffees. First, implement an abstract class...

    JAVA Problem:  Coffee    Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare (); } The prepare method will...

  • Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named...

    Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type(does not mention the data type of the variable coffeeType), price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public...

  • JAVA HELP Design a class named Employee. The class should keep the following information in fields:...

    JAVA HELP Design a class named Employee. The class should keep the following information in fields: Employee name Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. Hire date then, Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that extends the Employee class. The ProductionWorker class should have fields to...

  • In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a...

    In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a basic employee schema within a company. The Employee class will be an abstract class that will contain methods applicable to all employees. You will then create 2 classes called SoftwareEngineer and ProductManager. Both are different employee types based on occupation. You will create an interface called Developer which will consist of specific methods that apply to only Developers (e.g. SoftwareEngineer class will implement this,...

  • Homework-2 – Working with a class. Problem: Attached with this homework is code for a class...

    Homework-2 – Working with a class. Problem: Attached with this homework is code for a class called DroppedObject. This class is used to to store the state of a falling object. The problem this class/object can be used to solve is detailed below. Your task for this homework is to read and understand the attached class. Note this class is formatted like all classes should be with private variables, constructors, a toString method, getter and setter methods, and other relevant...

  • Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance...

    Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...

  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...

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