Exception Propagation: Recipe Validation System
Problem Description
Exception Propagation: Recipe Validation System
In this problem, you will create a program that validates a cooking time input, and displays either a recipe preparation success message or an error message from an exception that automatically propagates through method calls, to standard output.
Learning Objective: Learn to understand how exceptions propagate through method calls
Create system to validate recipe cooking time. When cooking time is negative value, throw IllegalArgumentException in validateCookingTime() method, and learn how exception propagates through prepareRecipe() method to main() method. Without explicitly re-throwing, exception automatically propagates to caller.
Example 1: Valid Cooking Time (30 minutes)
When input data of 30 minutes is given, validation in validateCookingTime() succeeds, processing proceeds normally through prepareRecipe() to main().
Input: 30
Output:
=== Recipe Validation ===
Cooking Time: 30 minutes
Validation: Success
━━━━━━━━━━━━━━━━
Status: Recipe prepared
```java
### Example 2: Negative Cooking Time (-10 minutes)
When input data of -10 minutes is given, IllegalArgumentException is thrown in validateCookingTime(). This exception passes through prepareRecipe() and is caught in main()'s catch block, displaying error message. PrepareRecipe() doesn't explicitly handle exception, but it automatically propagates upward to main().
```java
Input: -10
Output:
=== Recipe Validation ===
Cooking Time: -10 minutes
Validation: Failed
━━━━━━━━━━━━━━━━
Error: Cooking time must be positive
```java
### Example 3: Boundary Value (0 minutes)
When input data of 0 minutes is given, validation succeeds as it's not negative value. Cooking time 0 minutes is valid as special case meaning "instant, no preparation needed".
```java
Input: 0
Output:
=== Recipe Validation ===
Cooking Time: 0 minutes
Validation: Success
━━━━━━━━━━━━━━━━
Status: Recipe prepared
```java
## Input
Line 1: Cooking time (minutes)
## Output
```java
=== Recipe Validation ===
Cooking Time: [time] minutes
Validation: Success
━━━━━━━━━━━━━━━━
Status: Recipe prepared
```java
Or when exception occurs:
```java
=== Recipe Validation ===
Cooking Time: [time] minutes
Validation: Failed
━━━━━━━━━━━━━━━━
Error: Cooking time must be positive
Test Cases
※ Output examples follow programming industry standards
30
=== Recipe Validation === Cooking Time: 30 minutes Validation: Success ━━━━━━━━━━━━━━━━ Status: Recipe prepared
-10
=== Recipe Validation === Cooking Time: -10 minutes Validation: Failed ━━━━━━━━━━━━━━━━ Error: Cooking time must be positive
Your Solution
You have 10 free executions remaining
