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