State Pattern - Lab 1
Provide the classes 1) Drive and 2) Bicycle and demonstrate their usage in the Lab1 driver using the starter code below:
Final Solution UML:
Code Starter
TravelMode.java
package StatePatternLabOne;
public interface TravelMode {
Object getETA();
Object getDirection();
}
Walk.java
package StatePatternLabOne;
public class Walk implements TravelMode {
@Override
public Object getETA() {
System.out.println("Calculating ETA (walking)");
return 4;
}
@Override
public Object getDirection() {
System.out.println("Calculating Direction (walking)");
return 4;
}
}
Bus.java
package StatePatternLabOne;
public class Bus implements TravelMode {
@Override
public Object getETA() {
System.out.println("Calculating ETA (transit)");
return 3;
}
@Override
public Object getDirection() {
System.out.println("Calculating Direction (transit)");
return 3;
}
}
DirectionService.java
Lab1.java (driver)
Current Output: