JAVA ASSIGNMENT 2
Real-Life Scenario-Based Questions Using Conditional Statements in Java
1. Basic Control Statements (if, if-else, switch)
Scenario: Gym Membership Eligibility
A gym offers membership discounts based on age:
- If the person is below 18, they get a 50% discount.
- If the person is 65 or older, they get a 30% discount.
- Otherwise, they pay the full price.
Question:
Write a Java program that takes a user's age as input and determines the membership
discount they receive.
2. Type Conversion and Casting
Scenario: Currency Converter for Online Shopping
A shopping website allows users to pay in different currencies. The system accepts prices in
USD (double type) but sometimes users enter whole numbers (int type).
Question:
Write a Java program that converts an integer price to a double before processing the
payment.
3. Exception Handling
Scenario: Bank Withdrawal System
A bank's ATM system should prevent users from withdrawing more money than their
account balance. If the withdrawal amount exceeds the balance, an
InsufficientFundsException should be thrown.
Question:
Write a Java program that simulates a bank withdrawal system. If the user tries to withdraw
more than their balance, catch the exception and display an error message.
4. Arrays and Loops with Conditional Statements
Scenario: Student Grade Classification
A university classifies students based on their final exam scores:
- 90 and above → "A (Excellent)"
- 80 - 89 → "B (Good)"
- 70 - 79 → "C (Average)"
- Below 70 → "F (Fail)"
Question:
Write a Java program that takes an array of student scores and prints their respective
grades.
5. GUI with Swing & Event Handling
Scenario: Login Authentication
A company's login system verifies user credentials. If the username is "admin" and the
password is "1234", access is granted; otherwise, an error message is displayed.
Question:
Create a simple GUI-based login system using Swing where users enter a username and
password. Use event handling to check if the entered credentials are correct.