idastan97

CSCI152 L2 P1

Jan 12th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. public class Automobile {
  2.     private boolean engineRunning;
  3.     private double speed;
  4.     private String lis;
  5.     public Automobile(String l){
  6.         engineRunning=false;
  7.         speed=0.0;
  8.         lis=l;
  9.     }
  10.     public void startCar(){
  11.         engineRunning=true;
  12.     }
  13.     public void pressGassPedal(){
  14.         if (engineRunning){
  15.             speed=speed+10.0;
  16.         }
  17.     }
  18.     public void pressBrake(){
  19.         speed=0.0;
  20.     }
  21.     public void shutdown(){
  22.         engineRunning=false;
  23.     }
  24.     public boolean isEngineRunning(){
  25.         return engineRunning;
  26.     }
  27.     public double getSpeed(){
  28.         return speed;
  29.     }
  30.     public String toString(){
  31.         return "License Plate: " + lis + ", engine running: " + engineRunning +
  32.                 ", speed: " + speed + ".";
  33.     }
  34. }
  35.  
  36. public class AutoTest {
  37.     public static void main(String[] args){
  38.         Automobile car1 = new Automobile("B247LMN");
  39.         Automobile car2 = new Automobile("A123SAN");
  40.         car1.startCar();
  41.         car1.pressGassPedal();
  42.         car1.pressGassPedal();
  43.         car2.pressGassPedal();
  44.         car2.startCar();
  45.         car2.pressGassPedal();
  46.         car2.pressBrake();
  47.         car2.shutdown();
  48.         System.out.println(car1);
  49.         System.out.println(car2);
  50.     }
  51. }
Add Comment
Please, Sign In to add comment