Loading...
Loading...
Loading...
A food order moves PLACED → PACKED → SHIPPED → DELIVERED, and can be cancelled only while it is PLACED or PACKED. Declare enum OrderStatus with PLACED, PACKED, SHIPPED, DELIVERED, CANCELLED and two methods: next() (DELIVERED and CANCELLED stay where they are) and canCancel().
The order starts at PLACED. Run the commands.
NEXT, CANCEL or STATUS.OLD -> NEW, or Already S when nothing changes. CANCEL: Cancelled, or Cannot cancel: S. STATUS: the status.Example
Input
5 NEXT NEXT CANCEL NEXT STATUS
Output
PLACED -> PACKED PACKED -> SHIPPED Cannot cancel: SHIPPED SHIPPED -> DELIVERED DELIVERED
After shipping, cancelling is no longer allowed.
Try the problem first. Open one hint at a time.
next() is a switch expression on this.
canCancel() is this == PLACED || this == PACKED.
For NEXT, keep the old status, move, and compare the two with ==.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor