Shreyas arya

Generation

generate functionMon, 23 Jan 2023

We need to create validators for each status. The validator will check if transition from current state is allowed or not.

public class Order { public enum State { PENDING, SUSPENDED, ACTIVE, CANCELLED, COMPLETED } Status state; public Order() { this.state = State.PENDING; } public void approve() { if (this.state == State.PENDING) { this.state = State.ACTIVE; } } public void suspend() { if (this.state == State.ACTIVE) { this.state = State.SUSPENDED; } } public void complete() { if (this.state == State.ACTIVE || this.state == State.SUSPENDED) { this.state = State.COMPLETED; } } public void cancel() { if (this.state == State.ACTIVE || this.state == State.PENDING) { this.state = State.CANCELLED; } } public

Want to kickstart your project?Use the new AI Studio to create your code