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: | 313 Weeks Ago, 6 Days 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