Home Page > > Details

Late homework Homework Assignment 1

 Homework Assignment 1

Late homework assignments will not be accepted, unless you have a valid written excuse  (medical, etc.). You must do 
this  assignment  alone.  No team  work  or  "talking with  your  friends"  will  be  accepted.  No  copying  from the  Internet. 
Cheating means zero.
Create  a  new  Eclipse  workspace  named  "Assignment1_1234567890"  on  the desktop  of  your  computer  (replace 
1234567890 with  your  student ID  number). For each  question  below,  create  a  new  project  in  that  workspace.  Call 
each project by its question number: "Question1", "Question2", etc. Answer all the questions below. At the end of 
the  assignment,  create  a  ZIP  archive  of the  whole  workspace  folder.  The  resulting  ZIP  file  must be  called
"Assignment1_1234567890.zip"  (replace 1234567890 with  your  student ID number). Upload  the  ZIP  file  on 
iSpace.
Question 1
You  are  a  software  engineer  who  has  to  write  the  software  for  a  car  transmission.  The  transmission  has  five  gears
numbered from 1 to 5 to move forward, one neutral gear position numbered 0 where the car does not move, and one 
reverse gear numbered -1 to move backward. The transmission has a clutch, and the driver of the car can only change 
gear if the driver is currently pushing the pedal for the clutch.
Write a Transmission class with the following UML specification:
+------------------------------------------+
| Transmission | +------------------------------------------+
| - clutchPedalPushed: boolean |
| - gear: int | +------------------------------------------+
| + Transmission() |
| + isClutchPedalPushed(): boolean |
| + pushClutchPedal(): void |
| + releaseClutchPedal(): void |
| + getGear(): int |
| + upShift(): void |
| + downShift(): void |
| + skipGears(int gear): void |
| + testTransmission(): void | +------------------------------------------+
where:
• clutchPedalPushed is  a  private  instance  variable  describing  whether  the  pedal  for  the  clutch of the 
transmission is currently pushed by the driver or not. • gear is a private instance variable describing the gear number in which the transmission currently is. • Transmission is a public constructor that creates a Transmission object. When a transmission is created, 
the pedal for its clutch is not currently being pushed and the transmission is in the neutral gear 0. • isClutchPedalPushed is a public method that returns as result a boolean indicating whether the driver is 
currently pushing the pedal for the clutch of the transmission or not. • pushClutchPedal is a public method that pushes the pedal for the clutch of the transmission; if the pedal is 
already currently being pushed then this method does nothing.
• releaseClutchPedal is a public method  that releases  the pedal  for  the clutch of  the transmission; if  the
pedal is currently not being pushed then this method does nothing. • getGear is a public method that returns the gear number in which the transmission currently is. • upShift is a public method that shifts the transmission up by one gear. The transmission can only shift up if 
the pedal for the clutch of the transmission is currently being pushed by the driver. If the pedal for the clutch of 
the transmission is not currently being pushed then the upShift method must print a message to the screen 
"Cannot shift up when the clutch is engaged"  and  the transmission does  not  change  gear.  If 
the  transmission is  already  in  gear 5 then  the upShift method  must print  a  message  "Cannot shift
higher than 5th gear" and the transmission does not change gear. • downShift is a public method that shifts the transmission down by one gear. The transmission can only shift
down if the pedal for the clutch of the transmission is currently being pushed by the driver. If the pedal for the 
clutch of the transmission is not currently being pushed then the downShift method must print a message to 
the  screen  "Cannot shift down when the clutch is engaged"  and  the transmission does  not
change  gear.  If  the  transmission is  already  in  gear -1  then  the downShift method  must print  a  message 
"Cannot shift lower than reverse gear" and the transmission does not change gear. • skipGears is a public method that shifts the transmission directly to the given gear.
o The transmission can only change gear if the pedal for the clutch is currently being pushed. If the pedal for 
the  clutch of  the transmission is not  currently  being  pushed then  the skipGears method must print a 
message  to  the  screen  "Cannot shift to another gear when the clutch is engaged" 
and the transmission does not change gear. o If the given gear number is strictly less than -1 or strictly bigger than 5 then the skipGears method must
print  a  message  "Cannot shift to gear XXX" (where  XXX is  replaced  in  the  real  output  by  the 
given gear number) and the transmission does not change gear. o If the given gear number is the same as the current gear of the transmission then the skipGears method 
must print a message  "Cannot shift to the same gear" and  the transmission does  not  change 
gear. o If  the  car  is  currently  moving  forward and  the  driver  tries  to  shift  to  the  reverse  gear,  or  if  the  car  is 
currently moving backward and the driver tries to shift to one of the forward gears, then the skipGears
method  must print  a  message  "Cannot reverse direction while moving" and  the 
transmission  does  not  change  gear.  (This  is  to  prevent  the  car  from  suddenly  switching  from  moving 
forward  to  moving  backward,  or  from  suddenly  switching  from  moving  backward  to  moving  forward, 
without going in between through the neutral gear position and stopping.) • testTransmission is a public static method that tests all the code in your Transmission class. Test all 
your methods from the simplest one first to the most complicated one last.
Once you have written the Transmission class, you can test it by adding the following code in a separate class:
public class Start {
public static void main(String[] args) {
Transmission.testTransmission();
} }
This code calls the static testTransmission method of the Transmission class, which should then run all your 
tests.
Here are a few extra instructions:
• Give meaningful names to your variables so we can easily know what each variable is used for in your program.
• Put  comments  in  your  code  (in  English!)  to  explain WHAT  your  code  is doing  and  also  to  explain  HOW  your 
program is doing it.
• Make sure all your code is properly indented (formatted). Your code should be beautiful to read.
Failure to follow these instructions will result in you losing points.
Contact Us - Email:99515681@qq.com    WeChat:codinghelp
Programming Assignment Help!