Skip to content

Instantly share code, notes, and snippets.

@R167
Created April 14, 2016 21:52
Show Gist options
  • Save R167/823f098dfb9bf7b785fb036d043f6218 to your computer and use it in GitHub Desktop.
Save R167/823f098dfb9bf7b785fb036d043f6218 to your computer and use it in GitHub Desktop.
AP CS assignment
public class Car extends SteeringVehicle {
// write all methods required
}
public interface Driveable {
public void turnRight();
public void turnLeft();
public void forward();
public void back();
public void stop();
}
public interface Fireable {
public void aim(PhysObject target)
public boolean fire();
}
public class Firearm implements Fireable {
// Code
}
public class Person extends PhysObject {
// more code
}
public abstract class PhysObject {
// 0-100
public double getDurability();
public double getSize();
}
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;
}
}
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()
}
}
// 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