019-006-001

Exception Handling Strategy: Cooking Timer Validation

Easy

Problem Description

exception handling Strategy: Cooking Timer Validation

Learning Objective: Learn to use appropriate exceptions according to situations

In this problem, you will create a program that reads maximum time and set time for a cooking timer from standard input, validates them by throwing IllegalArgumentException for invalid argument errors (e.g., negative values) or IllegalStateException for system limit violations (e.g., exceeding maximum time), and displays the validation result to standard output.

Create system to validate cooking timer settings. Use IllegalArgumentException for input value errors like negative time, and IllegalStateException for limit errors like exceeding maximum time. Selecting appropriate exceptions clearly communicates error type, making it easier for callers to handle appropriately.

Example 1: Valid Timer Setting (Max: 60min, Set: 30min)

Normal case setting 30 minutes on timer with 60 minute maximum. Passes both validations (argument validation and max check), displaying success message.

Input:
60
30

Output:
=== Cooking Timer Validator ===
Max Time: 60 min
Set Time: 30 min
Validation: Success
━━━━━━━━━━━━━━━━
Status: Timer setting is valid
```java

### Example 2: Input Value Error (Max: 60min, Set: -10min)
Negative set time is invalid as argument. ValidateSetTime() <a href="https://javadrill.tech/problems/008">method</a> throws IllegalArgumentException, processed as argument error. This clearly indicates "argument problem".
```java
Input:
60
-10

Output:
=== Cooking Timer Validator ===
Max Time: 60 min
Set Time: -10 min
Validation: Failed
━━━━━━━━━━━━━━━━
Error Type: IllegalArgumentException
Message: Set time must be positive
```java

### Example 3: Exceeds Maximum Error (Max: 30min, Set: 60min)
Set time itself is valid (positive value), but exceeds maximum time. CheckMaxTime() method throws IllegalStateException, processed as state error. This clearly indicates "system limit problem".
```java
Input:
30
60

Output:
=== Cooking Timer Validator ===
Max Time: 30 min
Set Time: 60 min
Validation: Failed
━━━━━━━━━━━━━━━━
Error Type: IllegalStateException
Message: Exceeds max time (set: 60, max: 30)
```java

## Input
Line 1: Timer maximum time (minutes)
Line 2: Time to set (minutes)

## Output
Normal case:
```java
=== Cooking Timer Validator ===
Max Time: [max time] min
Set Time: [set time] min
Validation: Success
━━━━━━━━━━━━━━━━
Status: Timer setting is valid
```java

Input validation error:
```java
=== Cooking Timer Validator ===
Max Time: [max time] min
Set Time: [set time] min
Validation: Failed
━━━━━━━━━━━━━━━━
Error Type: IllegalArgumentException
Message: [error message]
```java

Exceeds maximum:
```java
=== Cooking Timer Validator ===
Max Time: [max time] min
Set Time: [set time] min
Validation: Failed
━━━━━━━━━━━━━━━━
Error Type: IllegalStateException
Message: [error message]

Test Cases

※ Output examples follow programming industry standards

Normal case
Input:
90
45
Expected Output:
=== Cooking Timer Validator ===
Max Time: 90 min
Set Time: 45 min
Validation: Success
━━━━━━━━━━━━━━━━
Status: Timer setting is valid
Normal case
Input:
20
45
Expected Output:
=== Cooking Timer Validator ===
Max Time: 20 min
Set Time: 45 min
Validation: Failed
━━━━━━━━━━━━━━━━
Error Type: IllegalStateException
Message: Exceeds max time (set: 45, max: 20)

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