019-006-002

Exception Handling Strategy: Recipe State Management

Easy

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

Normal case
Input:
30
prepared
Expected Output:
=== Recipe State Manager ===
Cooking Time: 30 minutes
State: prepared
Validation: Success
━━━━━━━━━━━━━━━━
Status: Recipe is valid
Normal case
Input:
-10
prepared
Expected Output:
=== Recipe State Manager ===
Cooking Time: -10 minutes
State: prepared
Validation: Failed
━━━━━━━━━━━━━━━━
Error Type: IllegalArgumentException
Message: Cooking time must be positive

Your Solution

Current Mode: My Code
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here

sc.close();
}
}
0 B / 5 MB

You have 10 free executions remaining