Question: Q1: Building a Car with automatic gear shifting with JAVA (Include comments in the code) You are building a car that will shift gear (automatically)

Q1: Building a Car with automatic gear shifting with JAVA (Include comments in the code)

You are building a car that will shift gear (automatically) base on the velocity changed according the following table:

Gears low high
1 0 10
2 11 20
3 21 30
4 31 40
5 41 >41

For this problem, there are three main components (vehicle, Car, and your specific car).

You can start with a base class Vehicle, and then create a Car class that inherits from this base class (Vehicle). From the Car class you can create a specific car (that you like) and inherits from the Car class. I like my MiniCooperS convertible and I use that for my example. From my mini, I want to be able steer (turn in 0 to 80 degrees) to change directions, and change velocity (accelerate (+/-) ) from pression of the gas paddle of my cool car. However, the actual steering and moving are done in the vehicle level. The steeling and speed adjustment information come from the UI level (your main ( ) program -given) and pass onto the mini-Coopers for processing. In your design, you will want to decide where to put the appropriate state and behaviors (fields and methods) into all the three classes. What fields and methods should go to which Classes?

All the instance variables must be private. (10 points)

Your Vehicle class should have name, engine size, velocity, direction (0-80). It knows how to steer (direction) and move (velocity, direction). Remember, the direction and velocity setting are cumulative (it updates from the previous value to become a current value).

Your Car class (extends from Vehicle) should have names, engine size, number of wheels, number of doors, number of gears, and manual or automatic transmission. Notice Vehicle has the name and size fields as well. Here is where you can use the super(.) in the constructor.

You need to have your specific car class (eg MiniCooperS) extends from the Car class) to do the gear change operation. In this class (eg MiniCooperS), you should have also have a readServiceMonths (int) field. You need to use the super(..) in your constructor to initialize some of the parameters. In this class (MiniCooperS), you should have a method (accelerate ( int rate) ) to do the gear switching based on the velocity change (see table above)

You need to add a toSting( ) method in all your classes to display (super or current) necessary attributes.

Your output display should look similar to the following example.

 Q1: Building a Car with automatic gear shifting with JAVA (Include

Vehicle.steer(): Vehicle.steer(): Vehicle.steer): turn 45 degrees. turn 55 degrees. turn 60 degrees Car.ShiftGear(): shift-> gear:3 Car.changeVel(): Velocity 30 direction 60 Vehicle.move Moving at 30 in direction 60 Car.ShiftGear(): shift-> gear:4 Car.changeVel(): Velocity 50 direction 60 Vehicle.move Moving at 50 in direction 60 Vehicle.steer(): turn 80 degrees Car.ShiftGear(): shift-> gear:1 Car.changeVel(): Velocity 5 direction 80 Vehicle.move Moving at 5 in direction 80 Car.ShiftGear(): shift-> gear:1 Car.changeVel(): Velocity 10 direction 80 Vehicle.move) Moving at 10 in direction 80 Car Specfications:, Name-MiniCooperS, # of wheels-4, doors-2, sManual-false, Engine Size-3L roadServiceMonths-60

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!