Created
September 24, 2015 22:07
-
-
Save 0x8801/9ff4c688b02808b33770 to your computer and use it in GitHub Desktop.
Drive.java Rewritten with an Abstract Class and Methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Drive { | |
public abstract class GermanVehicles { | |
private String cost = "high"; | |
protected String speedometer = "kilometers" | |
public int maxSpeed = 280; | |
public int currentSpeed; | |
} | |
public abstract class Safety extends GermanVehicles { | |
public void speedWarning(); //abstract | |
public void activateSpeedGovernor(int speed); | |
} | |
public class MercedesBenz extends Safety { | |
public void speedWarning() { | |
System.out.println("The Benz is going too fast. Please slow down"); | |
} | |
public void activateSpeedGovernor(int speed) { | |
currentSpeed = maxSpeed - speed; | |
System.out.println("Benz slowed down to " + currentSpeed); | |
} | |
} | |
public static void main(String[] args) { | |
MercedesBenz S550 = new MercedesBenz(); | |
while(1){ | |
if(currentSpeed==maxSpeed){ | |
S550.speedWarning(); | |
S550.activateSpeedGovernor(50); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment