005-003-002

Nested If: Ticket Price

Easy

Problem Description

Nested If: Ticket Price

Learning Objective: Judge multiple conditions with nested if statements

Create program that inputs age and student status to determine ticket price. Learn nested structure by first checking age, then student status within that.

Rules:

  • 18+: 1500 yen for students, 2000 yen for general
  • Under 18: 1000 yen for students, 1200 yen for general

Input

Line 1: Age (integer)
Line 2: Student flag (true=student, false=general)

Output

Age: [age] years old
Student: [status]
Ticket price: [price] yen
```java

## Examples

### Example 1: Adult student
Input:
```java
20
true
```java
Output:
```java
Age: 20 years old
Student: true
Ticket price: 1500 yen
```java

### Example 2: Minor general
Input:
```java
15
false
```java
Output:
```java
Age: 15 years old
Student: false
Ticket price: 1200 yen

Test Cases

※ Output examples follow programming industry standards

Input:
20
true
Expected Output:
Age: 20 years old
Student: true
Ticket price: 1500 yen
Input:
25
false
Expected Output:
Age: 25 years old
Student: false
Ticket price: 2000 yen
Input:
18
true
Expected Output:
Age: 18 years old
Student: true
Ticket price: 1500 yen
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
// ユーザー入力を読むためのキーボードからの入力を読むScannerオブジェクトを作成
Scanner sc = new Scanner(System.in);
// ユーザーからの入力値を読んで格納
int age = sc.nextInt();
boolean isStudent = sc.nextBoolean();
// コンソール経由でユーザーに出力を表示
System.out.println("Age: " + age + " years old");
// コンソール経由でユーザーに出力を表示
System.out.println("Student: " + isStudent);
int price;
// 条件をチェック
if (age >= 18) {
// 条件をチェック
if (isStudent) {
price = 1500;
} else {
price = 2000;
}
} else {
// 条件をチェック
if (isStudent) {
price = 1000;
} else {
price = 1200;
}
}
// コンソール経由でユーザーに出力を表示
System.out.println("Ticket price: " + price + " yen");
}
}

0 B / 5 MB

You have 10 free executions remaining