Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help on this java homework. I realize that this is a big question and if I need to break it up into multiple questions

Need help on this java homework. I realize that this is a big question and if I need to break it up into multiple questions I will do so.

If I can't get the complete answer I would appreciate one class example so that I can build from there. I am stuck on how to keep track and manipulate the values needed for variables.

Building a virtual Car gear shifter with associated velocity plus directions

You are building a car that will shift gear (automatically) based on the velocity ranges of the following table: (the numbers are integers, low/high are in mph but dont worry about the unit for this question)

image text in transcribed

You can start with a base class Vehicle, and then create a Car class that inherits from this base class Vehicle. You can then create another class which is a specific type of car that inherits from the Car class. You can choose any hot car that you like. Mine is a MiniCooperS convertible. Please build these classes in their separate files. There should be 4 files (classes) with the given main file below included in the 4 files. Vehicle > Car > MiniCooperS and Main

For your car class, you want to be able to steer directions (turn in 0 to 80 degrees) and change velocity (accelerate(+), decelerate(-)). The gears change based on the velocity range of the table above. After every velocity change, your program needs to report the gear shift values, and the vehicle movement parameters (speed, direction) cumulatively. After every direction change, your program needs to report the cumulative changes of the direction as well.

Your output display should look similar to the following.

Increase speed by 35 from 0 => new velocity is 35

Car.ShiftGear(): shift from 1 -> gear: 4

Vehicle.move(): Moving at 35 in direction 0

Vehicle.steer(): turn from 0 to 40 degrees

Vehicle.steer(): turn from 40 to 55 degrees

Vehicle.steer(): turn from 55 to 50 degrees

Increase speed by 25 from 35 => new velocity is 60

Car.ShiftGear(): shift from 4 -> gear: 5

Vehicle.move(): Moving at 60 in direction 50

Vehicle.steer(): turn from 50 to 75 degrees

Reduce speed by-20 from 60 => new velocity is 40

Car.ShiftGear(): shift from 5 -> gear: 4

Vehicle.move(): Moving at 40 in direction 75

Increase speed by 5 from 40 => new velocity is 45

Car.ShiftGear(): shift from 4 -> gear: 5

Vehicle.move(): Moving at 45 in direction 75

Vehicle.steer(): turn from 75 to 87 degrees

Reduce speed by-8 from 45 => new velocity is 37

Car.ShiftGear(): shift from 5 -> gear: 4

Vehicle.move(): Moving at 37 in direction 87

Car Specfications:

name = MiniCooperS ,

size = 3L ,

# of wheels =4,

doors=2,

isManual = true,

Engine Size= 3L

roadServiceMonths = 12

From the above result printouts, it appears that you will need: Name, # of Wheels, doors, isManual (or automatic), Engine size, roadServiceMonths, Current Gear value, method to change gear, Current velocity, method to change velocity (accelerate, decelerate), method to steer() to change and update directions, method to move() to change and update velocity. Remember, the direction and velocity setting are cumulative (it updates from the previous value to become a current value). You will have to decide on which class is more appropriate to have the above states and methods. All your states should be private. You will need to have getters to get the private data (eg getName() method returns the car name via an object.getName() )

The following are the suggested arrangement for all the class.

Dont forget to use super(.) to initialize the super class and toString() to help in displaying results.

Your Vehicle class should have name, engine size, velocity, direction(0-360). It knows how to steer (direction) and move (velocity, direction). 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. You will need to use super() along the class hierarchy tree to initialize various variables.

You need to have your specific car class (eg MiniCooperS) extends from Car (class)) to do the gear change operation. In this class (eg MiniCooperS), you should have a readServiceMonths (int) field. You need to use the super(..) in your constructor to initialize some of the parameters of the parent class. I put the gear changing codes in the Car class.

Main.Java:

package Assignment2;

public class Main {

public static void main(String[] args) {

final int roadServiceMonth = 12; MiniCooperS mini = new MiniCooperS(roadServiceMonth); // steer() is defined in Vehicle // start car and accelerate from 0 to 30 mpp // show gear setting, and move values(speed,direction) (total speed, direction) mini.accelerate(35); // change direction (steer) 3 times (45, 10, -5) mini.steer(40); mini.steer(15); mini.steer(-5);

// increase speed by 20 ; show gear setting, move values mini.accelerate(25); // change direction (20) ; mini.steer(25); // change speed by (-20, 5); mini.accelerate(-20); mini.accelerate(5); // change direction (10) : Reduce speed (-10) mini.steer(12); mini.accelerate(-8); System.out.println(mini); // toString() in mini will display the stuff } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions

Question

Can options that are written qualify for hedge accounting?

Answered: 1 week ago

Question

C y 3x 30x 63 completing the square C. + 63 (corrpleting the square

Answered: 1 week ago

Question

What is the relationship between humans?

Answered: 1 week ago

Question

What is the orientation toward time?

Answered: 1 week ago