Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

All your code ( except tests ) should be in a package called vehicle. Write an interface ManualTransmission that offers only the following methods: getStatus

All your code (except tests) should be in a package called "vehicle".
Write an interface ManualTransmission that offers only the following methods:
getStatus : Return the status of this transmission as a String without any additional parameters.
getSpeed : Get the current speed of the vehicle as a whole number.
getGear : Get the current gear of the vehicle as a whole number.
increaseSpeed : Increase the speed by a fixed amount without changing gears and return the resulting transmission object. If the speed cannot be increased, then it should return an object with the same speed as before. The speed change amount is up to the implementation and is not an argument of this method.
decreaseSpeed : Decrease the speed by a fixed amount without changing gears and return the resulting transmission object. If the speed cannot be decreased, then it should return an object with the same speed as before. The speed change amount is up to the implementation and is not an argument of this method.
increaseGear : Increase the gear by one without changing speed and return the resulting transmission object. If the gear cannot be increased, then it should return an object with the same gear as before.
decreaseGear : Decrease the gear by one without changing speed and return the resulting transmission object. If the gear cannot be decreased, then it should return an object with the same gear as before.
Write an implementation called RegularManualTransmission that implements the ManualTransmission interface. It must have the following characteristics:
The speed changes by 1 at a time.
The transmission supports exactly 5 gears, numbered 1 through 5. Gear 1 has the lowest speed range.
The class offers a constructor that takes the speed ranges for the 5 gears as two integral numbers each: low and high. Thus it takes arguments as l1,h1,l2,h2,...,l5,h5. For each gear x, lx should be less than or equal to hx. Furthermore the lower speed for gear 1 should be strictly lesser than that of gear 2, and so on. Finally (only) adjacent-gear ranges may overlap (e.g. l2 may be between l1 and h1, etc.) but the ranges cannot be non-overlapping (i.e. each speed is covered by a gear range). The lower speed of the first gear should be 0, and the highest speed in the last gear represents the speed limit of the vehicle (it cannot go faster than this). If any of these conditions are not fulfilled by the inputs then the constructor should throw an IllegalArgumentException with an appropriate message.
The status message it returns is exactly one of the following possibilities (depending on the state of the transmission and the last thing that was attempted):
"OK: everything is OK.": this is the status if the speed was changed successfully without changing gears, or the gear was changed successfully without changing speed.
"OK: you may increase the gear.": this is the status if the speed was increased successfully, but it is now within the range of the next gear (remember that adjacent gear ranges may overlap)
"OK: you may decrease the gear.": this is the status if the speed was decreased successfully, but it is now within the range of the previous gear (remember that adjacent gear ranges may overlap)
"Cannot increase speed, increase gear first.": this is the status if the speed cannot be increased more unless the gear is increased first. This implies that the intended speed is too high for the current gear.
"Cannot decrease speed, decrease gear first.": this is the status if the speed cannot be decreased more unless the gear is decreased first. This implies that the intended speed is too low for the current gear.
"Cannot increase gear, increase speed first.": this is the status if the gear cannot be increased more unless the speed is increased first. This implies that the current speed will be too low for the next gear.
"Cannot decrease gear, decrease speed first.": this is the status if the gear cannot be decreased more unless the speed is decreased first. This implies that the current speed will be too high for the previous gear.
"Cannot increase speed. Reached maximum speed.": this is the status if the speed cannot be increased as it will go beyond the speed limit of the vehicle
"Cannot decrease speed. Reached minimum speed.": this is the status if the speed cannot be decreased as it is already 0
"Cannot increase gear. Reached maximum gear.": this is the status if the gear cannot be increased as it is already in gear 5
"Cannot decrease gear. Reached minimum gear.": this is the status if the gear cannot be decreased as it is already in gear 1
An object should start in the first gear with zero speed and a status of "OK: everything is OK.".
Write tests for this class (create an empty RegularManualTransmission , then write tests and finally fill the implementation).

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

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions