0% found this document useful (0 votes)
5 views2 pages

Java Conditional Statements

The document outlines a Java assignment consisting of five scenarios that require the use of conditional statements, type conversion, exception handling, arrays, loops, and GUI with event handling. Each scenario includes a specific question prompting the creation of a Java program to address real-life situations such as gym membership eligibility, currency conversion, bank withdrawals, student grade classification, and login authentication. The assignment aims to enhance practical programming skills through these varied applications.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Java Conditional Statements

The document outlines a Java assignment consisting of five scenarios that require the use of conditional statements, type conversion, exception handling, arrays, loops, and GUI with event handling. Each scenario includes a specific question prompting the creation of a Java program to address real-life situations such as gym membership eligibility, currency conversion, bank withdrawals, student grade classification, and login authentication. The assignment aims to enhance practical programming skills through these varied applications.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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.

You might also like