0% found this document useful (0 votes)
48 views4 pages

Story Based Java Coding Questions (Editable)

The document contains beginner-friendly Java coding questions organized into various categories including variables, decision making, looping, command line arguments, arrays, classes and objects, and a combined logic problem. Each question is framed as a story to provide context for coding tasks such as calculating bank balances, electricity bills, and student grades. The questions are designed for exam preparation and can be edited for practice purposes.

Uploaded by

parnikadesk
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views4 pages

Story Based Java Coding Questions (Editable)

The document contains beginner-friendly Java coding questions organized into various categories including variables, decision making, looping, command line arguments, arrays, classes and objects, and a combined logic problem. Each question is framed as a story to provide context for coding tasks such as calculating bank balances, electricity bills, and student grades. The questions are designed for exam preparation and can be edited for practice purposes.

Uploaded by

parnikadesk
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Story Based Java Coding Questions

(Beginner Friendly | Exam Oriented | Editable Format)

1. Variables, Data Types & Operators

Q1. Bank Balance Story

Ravi opens a bank account with an initial balance. He deposits some money and withdraws a certain
amount. - Store initial balance, deposit amount, and withdrawal amount. - Calculate and display the final
balance.

Q2. Electricity Bill Story

The electricity board charges: - ₹5 per unit for the first 100 units - ₹7 per unit for remaining units

Write a program to calculate and display the electricity bill for given units consumed.

Q3. Shopping Discount Story

A shop offers: - 10% discount if total bill amount is more than ₹5000 - No discount otherwise

Calculate and display the final amount to be paid.

2. Decision Making Statements

Q4. Exam Result Story

Based on student marks: - Marks ≥ 90 → Grade A - 75–89 → Grade B - 50–74 → Grade C - Below 50 → Fail

Display the grade using decision statements.

Q5. Traffic Signal Story

Given a traffic light color: - Red → Stop - Yellow → Ready - Green → Go

Use a switch statement to display the correct action.

1
3. Looping Statements

Q6. Library Fine Story

A library charges ₹2 fine per day for late book returns. - Input number of late days - Use a loop to calculate
total fine

Q7. Water Tank Story

A water tank fills at the rate of 5 liters per minute. - Calculate total water filled in n minutes using a loop

Q8. Festival Lights Story

A street has 10 houses. Each house switches on lights one after another. Use a loop to display the status of
each house.

4. Command Line Arguments

Q9. Bus Ticket Story

Ticket price and number of passengers are given through command line arguments. - Calculate and display
total ticket fare.

5. Arrays

Q10. Student Marks Story (1D Array)

Store marks of 5 students in a one-dimensional array. - Calculate total and average marks.

Q11. School Classroom Story (2D Array)

A school has 3 classes and each class has 4 students. - Store marks in a 2D array - Find the highest mark in
the school

Q12. Cricket Match Story (Jagged Array)

A cricket team plays multiple matches: - Match 1 → 3 players - Match 2 → 4 players - Match 3 → 2 players

Store runs using a jagged array and display total runs scored in each match.

2
6. Classes & Objects

Q13. Student Information Story

Create a Student class with: - Name - Roll number - Marks

Create objects and display student details.

Q14. Car Showroom Story (Constructor)

Create a Car class with: - Brand name - Price

Use a constructor to initialize values and display car details.

Q15. Mobile Battery Story (Method Overloading)

Create a Mobile class. - One method displays battery percentage - Another overloaded method displays
battery percentage and charging status

Q16. Employee Details Story ( this keyword)

Create an Employee class where constructor parameters have the same names as instance variables. Use
this keyword to differentiate them.

Q17. College Registration Story ( static keyword)

Create a Student class where: - College name is common for all students (static) - Roll number and name
are different for each student

Display student details.

7. Combined Logic Problem

Q18. ATM Machine Story

Design an ATM system that: - Displays menu options (Deposit, Withdraw, Check Balance, Exit) - Uses switch
and loops - Continues until user chooses Exit

3
✔ Editable ✔ Beginner Friendly ✔ Perfect for Lab Exams & Practice

Common questions

Powered by AI

Method overloading allows different methods to share the same name but differ in parameter lists, enabling the 'Mobile Battery Story' to offer multiple ways to display battery information. This increases the adaptability of the code, allowing different information displays based on user needs without altering the method name, enhancing usability and maintainability .

The 'Car Showroom Story' demonstrates the use of constructor functions to initialize objects with initial values, such as brand name and price. This approach streamlines object creation, ensuring that objects are set up with necessary attributes at the start, which is a key principle in object-oriented programming for establishing robust and error-free software .

Story-based coding exercises, like the 'Bank Balance Story', contextualize programming concepts within relatable scenarios. This approach helps beginners understand the practical applications of variables and operators by simulating real-world situations, such as managing financial transactions. It encourages engagement and motivation, making abstract concepts more tangible and memorable .

Arrays play a crucial role in efficiently organizing and processing student marks by providing a structured format to store data for multiple classes. In a 2D array, each class can be represented as a row, and student marks as columns. This structure simplifies operations like finding the highest mark across the entire school by enabling straightforward iteration and comparison .

A switch statement is most suitable for the traffic signal scenario because it allows for a clear and concise mapping of specific input values (traffic light colors) to corresponding outputs (actions). Each case in the switch statement directly relates to a specific traffic signal color, enhancing readability and maintainability .

A jagged array is best suited for managing runs in multiple cricket matches as shown in the 'Cricket Match Story'. It allows different rows to store varying numbers of elements, reflecting the different number of players in each match. This flexibility makes it ideal for uneven data distributions typical in such scenarios .

Using a loop allows for efficient calculation of the total fine by iterating over the number of late days and incrementally adding the daily fine, which simplifies code management and reduces redundancy. This is especially beneficial when varying fine rates are introduced or adjusted dynamically based on different conditions .

The 'this' keyword resolves ambiguity when constructor parameter names and instance variable names are identical. By using 'this', the code specifies that the instance variable should be assigned the value from the parameter, avoiding common errors where parameters might inadvertently overwrite or misassign instance variables .

Loops facilitate the continuous operation of the ATM system, allowing users to repeatedly access the menu until they choose to exit. Switch statements handle different menu actions efficiently, enabling quick responses to user inputs like deposit or withdrawal. Together, they create a seamless, uninterrupted experience that mimics real-world ATM interactions .

The 'static' keyword is beneficial in this context as it allows the college name, which is a common attribute for all students, to be shared across all instances of the Student class. This reduces memory usage and keeps the college name consistent, simplifying updates and ensuring uniformity across the application .

You might also like