Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Vehicle
- {
- private int location;
- public Vehicle()
- {
- location = 0;
- }
- public Vehicle(int loc)
- {
- if (loc >= -20 && loc <= 20)
- location = loc;
- else if (loc < -20)
- location = -20;
- else
- location = 20;
- }
- void forward()
- {
- if (location < 20)
- location++;
- }
- void backward()
- {
- if (location > -20)
- location--;
- }
- int getLocation()
- {
- return location;
- }
- public String toString()
- {
- for (int i = -20; i < location; i++)
- System.out.print(" ");
- return "@";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement