005-003-006
Nested If: Ticket Price
Easy
Problem Description
Nested If: Ticket Price
Learning Objectives
Bloom Level: Apply
Practical Goals
- Implement 2-axis conditional branching with nested if statements
- Set boundary value (18 years) condition correctly
- Use boolean variable directly in condition expression
- Express 4-pattern fee calculation in structured code
Real-World Scenario
Scenario Type: Business
Business Context
You are developing a movie theater ticket sales system. You implement a "2-axis discount system" where prices vary by age and student ID presence.
This system is used in amusement parks, transportation, sports facilities, and many services. Master the pattern of determining fees from combinations of age category and attribute category.
Why This Matters
- Fee calculation is a basic function of many business systems
- 2-axis conditional branching is a frequent pattern in practice
- Accurate boundary value processing prevents billing errors
Problem Statement
Create program that inputs age and student status to determine ticket price.
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
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
99
1
2
3
4
5
6
7
8
9
10
›
⌄
⌄
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 5 free executions remaining
