Exception Handling Strategy: Recipe State Management
Problem Description
exception handling Strategy: Recipe State Management
In this problem, you will create a program that receives cooking time and recipe state as input, validates them by throwing IllegalArgumentException for input errors and IllegalStateException for state inconsistencies, and displays the result to standard output.
Learning Objective: Learn to use appropriate exceptions according to situations
Create system to manage recipe state. Use IllegalArgumentException for input validation errors, and IllegalStateException for state inconsistencies. Selecting appropriate exceptions clearly communicates error causes, making debugging and maintenance easier.
Input
Line 1: Cooking time (minutes)
Line 2: Recipe state ("prepared" or "cooking" or "invalid")
Output
Normal case:
=== Recipe State Manager ===
Cooking Time: [time] minutes
State: [state]
Validation: Success
━━━━━━━━━━━━━━━━
Status: Recipe is valid
Input validation error:
=== Recipe State Manager ===
Cooking Time: [time] minutes
State: [state]
Validation: Failed
━━━━━━━━━━━━━━━━
Error Type: IllegalArgumentException
Message: [error message]
State error:
=== Recipe State Manager ===
Cooking Time: [time] minutes
State: [state]
Validation: Failed
━━━━━━━━━━━━━━━━
Error Type: IllegalStateException
Message: [error message]
Test Cases
※ Output examples follow programming industry standards
30 prepared
=== Recipe State Manager === Cooking Time: 30 minutes State: prepared Validation: Success ━━━━━━━━━━━━━━━━ Status: Recipe is valid
-10 prepared
=== Recipe State Manager === Cooking Time: -10 minutes State: prepared Validation: Failed ━━━━━━━━━━━━━━━━ Error Type: IllegalArgumentException Message: Cooking time must be positive
Your Solution
You have 10 free executions remaining
