Created
April 14, 2016 21:52
-
-
Save R167/823f098dfb9bf7b785fb036d043f6218 to your computer and use it in GitHub Desktop.
AP CS assignment
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 Car extends SteeringVehicle { | |
// write all methods required | |
} |
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 interface Driveable { | |
public void turnRight(); | |
public void turnLeft(); | |
public void forward(); | |
public void back(); | |
public void stop(); | |
} |
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 interface Fireable { | |
public void aim(PhysObject target) | |
public boolean fire(); | |
} |
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 Firearm implements Fireable { | |
// Code | |
} |
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 Person extends PhysObject { | |
// more code | |
} |
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 abstract class PhysObject { | |
// 0-100 | |
public double getDurability(); | |
public double getSize(); | |
} |
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 abstract class SteeringVehicle extends PhysObject implements Driveable { | |
private double driveAngle = 0; | |
private double speed = 0; | |
public void turnRight() { | |
driveAngle = 30; | |
} | |
public void turnLeft() { | |
driveAngle = -30; | |
} | |
// ... | |
public void stop() { | |
speed = 0; | |
driveAngle = 0; | |
} | |
} |
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 Tank extends TreadVehicle implements Fireable { | |
public PhysObject target = null; | |
public void aim(PhysObject target) { | |
this.target = target; | |
} | |
public boolean fire() { | |
//something with getDurability() and getSize() | |
} | |
} |
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
// Treads can operate at different speeds | |
public abstract class TreadVehicle extends PhysObject implements Driveable { | |
public void setRight(double speed); | |
public void setLeft(double speed); | |
public void turnRight() { | |
setRight(-1); | |
setLeft(1); | |
// wait some time | |
stop(); | |
} | |
public void turnLeft() { | |
setRight(1); | |
setLeft(-1); | |
// wait some time | |
stop(); | |
} | |
// ... | |
public void stop() { | |
setLeft(0); | |
setRight(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment