Use the following files:
Auto.java
/**
Represents an automobile
*/
public class Auto implements Movement
{
private String carModel;
private String licensePlate;
private int position;
public Auto(String model, String licenseNum)
{
carModel = model;
licensePlate = licenseNum;
position = 0;
}
/**
Moves the auto to a new position
@param distance incremental amount to move
*/
public void move(int distance)
{
position += distance;
}
/**
Returns the current position of the auto
@return current position
*/
public String getPosition()
{
return carModel + " at position " + position;
}
}
MovementTester.java
/**
Tests the Auto and Ship classes and their
use of the Movement interface.
*/
public class MovementTester
{
public static void main(String[] args)
{
Movement myAuto = new Auto("Nissan Altima","JKX14R");
myAuto.move(35);
Movement myShip = new Ship(45,"Sea Serpent");
myShip.move(60);
System.out.println(myAuto.getPosition() + ", " + myShip.getPosition());
System.out.println("Expected: Nissan Altima at position 35, Sea Serpent at position 60");
}
private void moveAuto(Auto anAuto, int distance)
{
anAuto.move(distance);
}
private void moveShip(Ship aShip, int distance)
{
aShip.move(distance);
}
}
Ship.java
/**
Represents a ship.
*/
public class Ship implements Movement
{
private int sizeInFeet;
private String boatName;
private int position;
public Ship(int size, String name)
{
sizeInFeet = size;
boatName = name;
position = 0;
}
/**
Moves the ship to a new position
@param distance incremental amount to move
*/
public void move(int distance)
{
position += distance;
}
/**
Returns the current position of the ship
@return current position
*/
public String getPosition()
{
return boatName +" at position " + position;
}
}