The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 337 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Write a java program for a Toy Car Application. This Car Control can be used to command a electric toy car to power on, power off, go fast, slow down, turn left and turn right.
Create an interface "Controllable" which specifies the following abstract methods:
void powerOn();
void powerOff();
void turnRight();
void turnLeft();
void goFaster();
void slowDown();
Define an ElectricCar class that implements the following methods:
void powerOn ()
This method sets a flag to indicate the car is powered on
void powerOff ()
This method sets a flag to indicate the car is powered off.
void turnRight()
Turns the car by 5 degrees to the right.
void turnLeft()
Turns the car by 5 degrees to the left
void goFaster ()
Commands the car to move forward and increase the car speed by 2 mph.
void slowDown ()
Commands the car to reduce the speed by 2 mph.
String toString()
Override this method to output the car information.
Use the following main method to test your program:
public class ElectricCarApp {
public static void main(String[] args) {
Controllable toy = new ElectricCar();
toy.powerOn();
toy.goFaster();
toy.turnLeft();
System.out.println(toy);
toy.turnLeft();
System.out.println(toy);
toy.slowDown();
System.out.println(toy);
toy.powerOff();
toy.turnRight();
System.out.println(toy);
}
}
Expected Output:
car travels in 355 deg at the speed of 2 mph
car travels in 350 deg at the speed of 2 mph
car is stopped
car is powered off
----------- ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly