0% found this document useful (0 votes)
1 views41 pages

10-Hour Core Java Training Program

The document outlines a 10-hour Core Java training program consisting of 5 sessions, each lasting 2 hours and covering various programming topics such as fundamentals, arrays, OOP, and exception handling. Each session includes a structured set of programming problems categorized by difficulty, totaling 30 problems. The training is aimed at real-world applications in domains like retail, banking, and business operations.

Uploaded by

1hk23cs138
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)
1 views41 pages

10-Hour Core Java Training Program

The document outlines a 10-hour Core Java training program consisting of 5 sessions, each lasting 2 hours and covering various programming topics such as fundamentals, arrays, OOP, and exception handling. Each session includes a structured set of programming problems categorized by difficulty, totaling 30 problems. The training is aimed at real-world applications in domains like retail, banking, and business operations.

Uploaded by

1hk23cs138
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

10-HOUR CORE JAVA TRAINING PROGRAM

Real-World Programming Problem Solving


Total Duration: 10 Hours
Number of Sessions: 5
Duration per Session: 2 Hours
Questions per Session: 6
Difficulty Distribution per Session: 2 Easy + 2 Medium + 2 Hard
Total Programming Problems: 30

SESSION-WISE TRAINING STRUCTURE


Session Duration Topic Easy Medium Hard

Session
2 Hours Fundamentals, Conditions and Loops 2 2 2
1

Session
2 Hours Arrays and Strings 2 2 2
2

Session
2 Hours OOP – Classes, Objects and Constructors 2 2 2
3

Session OOP – Inheritance, Method Overriding and


2 Hours 2 2 2
4 Polymorphism

Session
2 Hours Exception Handling and Collections 2 2 2
5

SESSION 1 — FUNDAMENTALS, CONDITIONS AND


LOOPS
Topics Covered
Variables, Data Types, Operators, Scanner, if, if-else, nested if, switch, for loop, while loop, counters and
accumulators.

Training Domain
Retail, Banking and Business Operations

1
EASY QUESTION 1 — CUSTOMER PURCHASE DISCOUNT

Real-World Scenario

A retail store provides a 10% discount when the customer's purchase amount is ₹5,000 or more.

Question

Write a Java program to accept the purchase amount and calculate the final payable amount after applying
the discount.

Solution

import [Link];

public class PurchaseDiscount {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Enter purchase amount: ");


double amount = [Link]();

double discount = 0;

if (amount >= 5000) {


discount = amount * 0.10;
}

double finalAmount = amount - discount;

[Link]("Discount: Rs. " + discount);


[Link]("Final Amount: Rs. " + finalAmount);

[Link]();
}
}

Explanation

The purchase amount is stored using the double data type.

The condition:

2
if (amount >= 5000)

checks whether the customer qualifies for the discount.

The discount is calculated as 10% of the purchase amount.

Concepts Learned

Variables, data types, Scanner, arithmetic operators and if statement.

EASY QUESTION 2 — EMPLOYEE SHIFT IDENTIFICATION

Real-World Scenario

A company uses numeric shift codes.

1 represents Morning Shift.

2 represents Evening Shift.

3 represents Night Shift.

Question

Write a Java program to accept a shift code and display the corresponding employee shift.

Solution

import [Link];

public class EmployeeShift {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Enter shift code: ");


int code = [Link]();

switch (code) {
case 1:
[Link]("Morning Shift");
break;

case 2:

3
[Link]("Evening Shift");
break;

case 3:
[Link]("Night Shift");
break;

default:
[Link]("Invalid Shift Code");
}

[Link]();
}
}

Concepts Learned

switch, case, break and default.

MEDIUM QUESTION 1 — ELECTRICITY BILL CALCULATION

Real-World Scenario

An electricity board follows slab-based billing.

First 100 units: ₹2 per unit.

Next 200 units: ₹5 per unit.

Above 300 units: ₹8 per unit.

Question

Write a Java program to accept the number of electricity units consumed and calculate the total electricity
bill.

Solution

import [Link];

public class ElectricityBill {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

4
[Link]("Enter units consumed: ");
int units = [Link]();

double bill;

if (units <= 100) {


bill = units * 2;
} else if (units <= 300) {
bill = (100 * 2)
+ ((units - 100) * 5);
} else {
bill = (100 * 2)
+ (200 * 5)
+ ((units - 300) * 8);
}

[Link]("Electricity Bill: Rs. " + bill);

[Link]();
}
}

Example

For 350 units:

First 100 units = 100 × 2 = 200


Next 200 units = 200 × 5 = 1000
Remaining 50 = 50 × 8 = 400

Total Bill = Rs. 1600

Concepts Learned

if-else-if and slab-based business logic.

MEDIUM QUESTION 2 — ATM WITHDRAWAL VALIDATION

Real-World Scenario

An ATM permits a withdrawal only when the amount is a multiple of ₹100 and sufficient balance is available.

5
Question

Accept the account balance and withdrawal amount. Validate the withdrawal and display the remaining
balance.

Solution

import [Link];

public class ATMWithdrawal {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Enter balance: ");


double balance = [Link]();

[Link]("Enter withdrawal amount: ");


int amount = [Link]();

if (amount % 100 != 0) {
[Link](
"Amount must be a multiple of 100"
);
} else if (amount > balance) {
[Link]("Insufficient Balance");
} else {
balance = balance - amount;

[Link]("Withdrawal Successful");
[Link](
"Remaining Balance: Rs. " + balance
);
}

[Link]();
}
}

Concepts Learned

Modulus operator, validation and multiple conditions.

6
HARD QUESTION 1 — PARKING FEE CALCULATION

Real-World Scenario

A shopping mall charges parking fees using the following rules.

First 2 hours: ₹30 per hour.

Next 3 hours: ₹20 per hour.

Beyond 5 hours: ₹10 per hour.

Maximum daily parking charge: ₹200.

Question

Write a Java program to calculate the parking fee based on the number of hours parked.

Solution

import [Link];

public class ParkingFee {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Enter parking hours: ");


int hours = [Link]();

int fee;

if (hours <= 2) {
fee = hours * 30;
} else if (hours <= 5) {
fee = (2 * 30)
+ ((hours - 2) * 20);
} else {
fee = (2 * 30)
+ (3 * 20)
+ ((hours - 5) * 10);
}

if (fee > 200) {


fee = 200;
}

7
[Link]("Parking Fee: Rs. " + fee);

[Link]();
}
}

Concepts Learned

Complex conditions, slab calculations and business rules.

HARD QUESTION 2 — WEEKLY SALES PERFORMANCE ANALYSIS

Real-World Scenario

A retail manager records sales for seven days. The manager wants to calculate total sales, average sales,
highest daily sales and the number of days the ₹50,000 sales target was achieved.

Question

Write a Java program to accept sales for seven days and generate a weekly sales summary.

Solution

import [Link];

public class SalesAnalysis {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

double total = 0;
double highest = 0;
int targetDays = 0;

for (int day = 1; day <= 7; day++) {


[Link](
"Enter sales for Day " + day + ": "
);

double sales = [Link]();

total = total + sales;

if (sales > highest) {


highest = sales;
}

8
if (sales >= 50000) {
targetDays++;
}
}

double average = total / 7;

[Link]("Total Sales: Rs. " + total);


[Link]("Average Sales: Rs. " + average);
[Link]("Highest Sales: Rs. " + highest);
[Link](
"Target Achieved Days: " + targetDays
);

[Link]();
}
}

Concepts Learned

for loop, accumulator, counter and maximum value identification.

SESSION 2 — ARRAYS AND STRINGS


Topics Covered
One-dimensional arrays, array input, traversal, searching, maximum and second maximum, String
methods, substring, character processing and word analysis.

Training Domain
Student, Inventory and Customer Data Processing

EASY QUESTION 1 — STUDENT MARK ANALYSIS

Real-World Scenario

A faculty member wants to calculate the average marks of five students.

9
Question

Store five student marks in an array and calculate the average mark.

Solution

import [Link];

public class StudentAverage {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

int[] marks = new int[5];


int total = 0;

for (int i = 0; i < [Link]; i++) {


[Link](
"Enter mark " + (i + 1) + ": "
);

marks[i] = [Link]();
total += marks[i];
}

double average =
(double) total / [Link];

[Link]("Average Mark: " + average);

[Link]();
}
}

Concepts Learned

Array creation, indexing and traversal.

EASY QUESTION 2 — CUSTOMER NAME FORMATTING

Real-World Scenario

A customer registration application stores names in uppercase.

10
Question

Accept a customer name and display the name in uppercase and the total number of characters.

Solution

import [Link];

public class CustomerName {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Enter customer name: ");


String name = [Link]();

[Link](
"Uppercase: " + [Link]()
);

[Link](
"Characters: " + [Link]()
);

[Link]();
}
}

Concepts Learned

String, toUpperCase and length.

MEDIUM QUESTION 1 — PRODUCT ID SEARCH

Real-World Scenario

An inventory application stores product IDs. The inventory manager wants to check whether a product
exists.

Question

Store product IDs in an array and search for a product ID entered by the user.

11
Solution

import [Link];

public class ProductSearch {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

int[] productIds = {
101, 105, 110, 125, 150
};

[Link]("Enter Product ID: ");


int searchId = [Link]();

boolean found = false;

for (int id : productIds) {


if (id == searchId) {
found = true;
break;
}
}

if (found) {
[Link]("Product Found");
} else {
[Link]("Product Not Found");
}

[Link]();
}
}

Concepts Learned

Linear search, enhanced for loop and boolean flag.

MEDIUM QUESTION 2 — EMAIL DOMAIN EXTRACTION

Real-World Scenario

A marketing company wants to identify the email service provider used by a customer.

12
Question

Accept an email address and extract the domain.

For example:

student@[Link]

Output:

[Link]

Solution

import [Link];

public class EmailDomain {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Enter email: ");


String email = [Link]();

int position = [Link]('@');

if (position != -1) {
String domain =
[Link](position + 1);

[Link]("Domain: " + domain);


} else {
[Link]("Invalid Email");
}

[Link]();
}
}

Concepts Learned

indexOf, substring and String validation.

13
HARD QUESTION 1 — SECOND HIGHEST PRODUCT PRICE

Real-World Scenario

An e-commerce manager wants to find the second highest product price without sorting the complete list.

Question

Find the second highest value in an array of product prices without using sorting.

Solution

public class SecondHighestPrice {


public static void main(String[] args) {
double[] prices = {
45000,
75000,
32000,
95000,
68000
};

double highest =
Double.NEGATIVE_INFINITY;

double secondHighest =
Double.NEGATIVE_INFINITY;

for (double price : prices) {


if (price > highest) {
secondHighest = highest;
highest = price;
} else if (
price > secondHighest
&& price != highest
) {
secondHighest = price;
}
}

[Link](
"Second Highest Price: Rs. "
+ secondHighest
);
}
}

14
Concepts Learned

Array analysis and comparison logic.

HARD QUESTION 2 — CUSTOMER REVIEW WORD FREQUENCY

Real-World Scenario

An e-commerce company wants to perform simple sentiment-related analysis on customer reviews.

Question

Count the number of times the word good appears in a customer review. The comparison must be case-
insensitive.

Solution

import [Link];

public class ReviewAnalysis {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Enter review: ");


String review = [Link]();

String[] words =
[Link]().split("\\s+");

int count = 0;

for (String word : words) {


if ([Link]("good")) {
count++;
}
}

[Link](
"'good' appears " + count + " times"
);

[Link]();
}
}

15
Concepts Learned

split, String array, equals and text processing.

SESSION 3 — OOP: CLASSES, OBJECTS AND


CONSTRUCTORS
Topics Covered
Class definition, fields, methods, object creation, constructors, parameterized constructors, constructor
overloading, this keyword and arrays of objects.

Training Domain
Banking, Product and Student Management

EASY QUESTION 1 — BANK ACCOUNT OBJECT

Real-World Scenario

A bank wants to represent customer accounts using Java objects.

Question

Create a BankAccount class containing account number, customer name and balance. Create an object
and display the account details.

Solution

class BankAccount {
int accountNumber;
String customerName;
double balance;

void displayAccount() {
[Link](
"Account Number: " + accountNumber
);
[Link](
"Customer Name: " + customerName
);

16
[Link](
"Balance: Rs. " + balance
);
}
}

public class BankApplication {


public static void main(String[] args) {
BankAccount account = new BankAccount();

[Link] = 1001;
[Link] = "Arun Kumar";
[Link] = 50000;

[Link]();
}
}

Concepts Learned

Class, object, fields and methods.

EASY QUESTION 2 — PRODUCT CONSTRUCTOR

Real-World Scenario

An e-commerce system creates a product object whenever a new product is registered.

Question

Create a Product class with product ID, product name and price. Use a parameterized constructor to
initialize the product.

Solution

class Product {
int productId;
String productName;
double price;

Product(
int productId,
String productName,
double price
) {

17
[Link] = productId;
[Link] = productName;
[Link] = price;
}

void displayProduct() {
[Link](
productId + " "
+ productName + " Rs. "
+ price
);
}
}

public class ProductApplication {


public static void main(String[] args) {
Product product =
new Product(
101,
"Laptop",
75000
);

[Link]();
}
}

Concepts Learned

Parameterized constructor and this keyword.

MEDIUM QUESTION 1 — EMPLOYEE SALARY OBJECT

Real-World Scenario

An HR system stores employee details and calculates annual salary.

Question

Create an Employee class with employee ID, name and monthly salary. Use a constructor and create a
method to calculate annual salary.

18
Solution

class Employee {
int employeeId;
String name;
double monthlySalary;

Employee(
int employeeId,
String name,
double monthlySalary
) {
[Link] = employeeId;
[Link] = name;
[Link] = monthlySalary;
}

double calculateAnnualSalary() {
return monthlySalary * 12;
}

void displayEmployee() {
[Link]("Employee: " + name);
[Link](
"Annual Salary: Rs. "
+ calculateAnnualSalary()
);
}
}

public class EmployeeApplication {


public static void main(String[] args) {
Employee employee =
new Employee(
101,
"Ayesha",
50000
);

[Link]();
}
}

Concepts Learned

Objects with business methods and constructor initialization.

19
MEDIUM QUESTION 2 — PRODUCT CONSTRUCTOR OVERLOADING

Real-World Scenario

An inventory system may create a product with or without an initial stock quantity.

Question

Create a Product class with overloaded constructors. One constructor accepts product name and price.
Another accepts product name, price and stock quantity.

Solution

class Product {
String name;
double price;
int stock;

Product(String name, double price) {


[Link] = name;
[Link] = price;
[Link] = 0;
}

Product(
String name,
double price,
int stock
) {
[Link] = name;
[Link] = price;
[Link] = stock;
}

void display() {
[Link](
name + " Rs. "
+ price + " Stock: "
+ stock
);
}
}

public class InventoryApplication {


public static void main(String[] args) {

20
Product product1 =
new Product("Laptop", 75000);

Product product2 =
new Product(
"Mobile",
50000,
25
);

[Link]();
[Link]();
}
}

Concepts Learned

Constructor overloading.

HARD QUESTION 1 — BANK ACCOUNT TRANSACTION OBJECT

Real-World Scenario

A bank wants each account object to maintain its own balance and perform deposit and withdrawal
operations.

Question

Create a BankAccount class with a constructor. Implement deposit, withdrawal and balance display
methods. Reject withdrawals when the balance is insufficient.

Solution

class BankAccount {
int accountNumber;
String customerName;
double balance;

BankAccount(
int accountNumber,
String customerName,
double balance
) {
[Link] = accountNumber;
[Link] = customerName;

21
[Link] = balance;
}

void deposit(double amount) {


if (amount > 0) {
balance += amount;
}
}

void withdraw(double amount) {


if (amount <= balance) {
balance -= amount;
[Link](
"Withdrawal Successful"
);
} else {
[Link](
"Insufficient Balance"
);
}
}

void displayBalance() {
[Link](
customerName
+ " Balance: Rs. "
+ balance
);
}
}

public class BankingSystem {


public static void main(String[] args) {
BankAccount account =
new BankAccount(
1001,
"Arun",
50000
);

[Link](10000);
[Link](25000);
[Link]();
}
}

22
Concepts Learned

Object state, constructors and business methods.

HARD QUESTION 2 — STUDENT OBJECT PERFORMANCE ANALYSIS

Real-World Scenario

A college stores student records as objects and wants to identify the highest-scoring student.

Question

Create a Student class with USN, student name and marks. Store five Student objects in an array and
display the student having the highest marks.

Solution

class Student {
String usn;
String name;
int marks;

Student(
String usn,
String name,
int marks
) {
[Link] = usn;
[Link] = name;
[Link] = marks;
}

void display() {
[Link](
usn + " "
+ name + " "
+ marks
);
}
}

public class StudentAnalysis {


public static void main(String[] args) {
Student[] students = {
new Student(

23
"1HK24CS001",
"Arun",
82
),
new Student(
"1HK24CS002",
"Ayesha",
91
),
new Student(
"1HK24CS003",
"Sneha",
87
),
new Student(
"1HK24CS004",
"Rahul",
76
),
new Student(
"1HK24CS005",
"Imran",
89
)
};

Student topper = students[0];

for (Student student : students) {


if ([Link] > [Link]) {
topper = student;
}
}

[Link](
"Highest Scoring Student"
);

[Link]();
}
}

Concepts Learned

Array of objects, object comparison and object references.

24
SESSION 4 — OOP: INHERITANCE, METHOD
OVERRIDING AND POLYMORPHISM
Topics Covered
Inheritance, extends, super, method overriding, parent reference, child object, runtime polymorphism and
abstract classes.

Training Domain
Employee, Payment and Service Management

EASY QUESTION 1 — EMPLOYEE INHERITANCE

Real-World Scenario

A company maintains general employee details and additional salary details for permanent employees.

Question

Create an Employee parent class and a PermanentEmployee child class. Display employee name and
salary.

Solution

class Employee {
String name;

Employee(String name) {
[Link] = name;
}
}

class PermanentEmployee extends Employee {


double salary;

PermanentEmployee(
String name,
double salary
) {
super(name);
[Link] = salary;

25
}

void display() {
[Link]("Name: " + name);
[Link](
"Salary: Rs. " + salary
);
}
}

public class EmployeeApplication {


public static void main(String[] args) {
PermanentEmployee employee =
new PermanentEmployee(
"Arun",
50000
);

[Link]();
}
}

Concepts Learned

Inheritance, extends and super.

EASY QUESTION 2 — PAYMENT METHOD OVERRIDING

Real-World Scenario

An online shopping application supports different payment methods.

Question

Create a Payment class and override the processPayment() method in a UPIPayment class.

Solution

class Payment {
void processPayment() {
[Link](
"Processing General Payment"
);
}
}

26
class UPIPayment extends Payment {
@Override
void processPayment() {
[Link](
"Processing UPI Payment"
);
}
}

public class PaymentApplication {


public static void main(String[] args) {
UPIPayment payment =
new UPIPayment();

[Link]();
}
}

Concepts Learned

Method overriding.

MEDIUM QUESTION 1 — EMPLOYEE SALARY USING INHERITANCE

Real-World Scenario

Permanent employees receive a 20% allowance on basic salary.

Question

Create an Employee parent class and PermanentEmployee child class. Calculate the final salary.

Solution

class Employee {
String name;
double basicSalary;

Employee(
String name,
double basicSalary
) {
[Link] = name;
[Link] = basicSalary;

27
}
}

class PermanentEmployee extends Employee {

PermanentEmployee(
String name,
double basicSalary
) {
super(name, basicSalary);
}

double calculateSalary() {
return basicSalary
+ basicSalary * 0.20;
}
}

public class SalaryApplication {


public static void main(String[] args) {
PermanentEmployee employee =
new PermanentEmployee(
"Ayesha",
50000
);

[Link](
"Final Salary: Rs. "
+ [Link]()
);
}
}

Concepts Learned

Inheritance and inherited data usage.

MEDIUM QUESTION 2 — MULTIPLE PAYMENT TYPES

Real-World Scenario

An e-commerce application supports Credit Card and UPI payments.

28
Question

Override processPayment() in CreditCardPayment and UPIPayment. Use a parent Payment reference to


process both payment types.

Solution

class Payment {
void processPayment() {
[Link](
"Processing Payment"
);
}
}

class CreditCardPayment extends Payment {


@Override
void processPayment() {
[Link](
"Credit Card Payment Processed"
);
}
}

class UPIPayment extends Payment {


@Override
void processPayment() {
[Link](
"UPI Payment Processed"
);
}
}

public class PaymentSystem {


public static void main(String[] args) {
Payment payment;

payment = new CreditCardPayment();


[Link]();

payment = new UPIPayment();


[Link]();
}
}

29
Concepts Learned

Parent reference, child object and runtime polymorphism.

HARD QUESTION 1 — EMPLOYEE PAYROLL POLYMORPHISM

Real-World Scenario

Permanent employees receive a 20% allowance. Contract employees receive a 5% incentive.

Question

Design a payroll system using inheritance, method overriding and runtime polymorphism.

Solution

class Employee {
String name;
double basicSalary;

Employee(
String name,
double basicSalary
) {
[Link] = name;
[Link] = basicSalary;
}

double calculateSalary() {
return basicSalary;
}
}

class PermanentEmployee extends Employee {

PermanentEmployee(
String name,
double basicSalary
) {
super(name, basicSalary);
}

@Override
double calculateSalary() {
return basicSalary

30
+ basicSalary * 0.20;
}
}

class ContractEmployee extends Employee {

ContractEmployee(
String name,
double basicSalary
) {
super(name, basicSalary);
}

@Override
double calculateSalary() {
return basicSalary
+ basicSalary * 0.05;
}
}

public class PayrollSystem {


public static void main(String[] args) {
Employee[] employees = {
new PermanentEmployee(
"Arun",
50000
),
new ContractEmployee(
"Sneha",
40000
)
};

for (Employee employee : employees) {


[Link](
[Link]
+ " Salary: Rs. "
+ [Link]()
);
}
}
}

Concepts Learned

Inheritance hierarchy, overriding and runtime polymorphism.

31
HARD QUESTION 2 — DELIVERY CHARGE POLYMORPHISM

Real-World Scenario

A delivery company provides Standard, Express and Same-Day delivery.

Standard delivery costs ₹50.

Express delivery costs ₹100.

Same-Day delivery costs ₹200.

Question

Design a delivery charge calculation system using an abstract class and runtime polymorphism.

Solution

abstract class Delivery {


abstract double calculateCharge();

void displayCharge() {
[Link](
"Delivery Charge: Rs. "
+ calculateCharge()
);
}
}

class StandardDelivery extends Delivery {


double calculateCharge() {
return 50;
}
}

class ExpressDelivery extends Delivery {


double calculateCharge() {
return 100;
}
}

class SameDayDelivery extends Delivery {


double calculateCharge() {
return 200;
}
}

32
public class DeliverySystem {
public static void main(String[] args) {
Delivery[] deliveries = {
new StandardDelivery(),
new ExpressDelivery(),
new SameDayDelivery()
};

for (Delivery delivery : deliveries) {


[Link]();
}
}
}

Concepts Learned

Abstract class, abstract method and runtime polymorphism.

SESSION 5 — EXCEPTION HANDLING AND


COLLECTIONS
Topics Covered
try, catch, finally, throw, throws, custom exceptions, ArrayList, HashSet, HashMap and collections of objects.

Training Domain
Banking, Student and Inventory Applications

EASY QUESTION 1 — SAFE BILL DIVISION

Real-World Scenario

A restaurant divides the bill equally among customers. The application must handle a customer count of
zero.

Question

Accept the total bill and number of customers. Handle division by zero.

33
Solution

import [Link];

public class BillDivision {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

try {
[Link]("Enter bill: ");
int bill = [Link]();

[Link](
"Enter number of customers: "
);

int customers = [Link]();

int amount = bill / customers;

[Link](
"Amount per Customer: Rs. "
+ amount
);

} catch (ArithmeticException e) {
[Link](
"Customer count cannot be zero"
);
}

[Link]();
}
}

Concepts Learned

try, catch and ArithmeticException.

EASY QUESTION 2 — CUSTOMER LIST MANAGEMENT

Real-World Scenario

A service company wants to maintain a dynamic customer list.

34
Question

Store customer names using an ArrayList and display all customers.

Solution

import [Link];

public class CustomerList {


public static void main(String[] args) {
ArrayList<String> customers =
new ArrayList<>();

[Link]("Arun");
[Link]("Ayesha");
[Link]("Sneha");

for (String customer : customers) {


[Link](customer);
}
}
}

Concepts Learned

ArrayList, add and enhanced for loop.

MEDIUM QUESTION 1 — INVALID WITHDRAWAL EXCEPTION

Real-World Scenario

A banking application must reject withdrawal amounts greater than the account balance.

Question

Use throw to generate an exception when the withdrawal amount exceeds the available balance.

Solution

public class WithdrawalValidation {


public static void main(String[] args) {
double balance = 50000;
double withdrawal = 70000;

35
try {
if (withdrawal > balance) {
throw new IllegalArgumentException(
"Insufficient Balance"
);
}

balance -= withdrawal;

[Link](
"Balance: Rs. " + balance
);

} catch (IllegalArgumentException e) {
[Link]([Link]());
}
}
}

Concepts Learned

throw and exception generation.

MEDIUM QUESTION 2 — PRODUCT PRICE DIRECTORY

Real-World Scenario

A retail company wants to map product IDs to product prices.

Question

Use a HashMap to store product ID and price. Search for a product ID and display its price.

Solution

import [Link];

public class ProductDirectory {


public static void main(String[] args) {
HashMap<Integer, Double> products =
new HashMap<>();

[Link](101, 45000.0);
[Link](102, 75000.0);
[Link](103, 32000.0);

36
int searchId = 102;

if ([Link](searchId)) {
[Link](
"Price: Rs. "
+ [Link](searchId)
);
} else {
[Link](
"Product Not Found"
);
}
}
}

Concepts Learned

HashMap, put, containsKey and get.

HARD QUESTION 1 — CUSTOM INSUFFICIENT BALANCE EXCEPTION

Real-World Scenario

A banking application requires a specific exception for insufficient account balance.

Question

Create an InsufficientBalanceException and use it during withdrawal.

Solution

class InsufficientBalanceException
extends Exception {

InsufficientBalanceException(
String message
) {
super(message);
}
}

class Account {
private double balance;

37
Account(double balance) {
[Link] = balance;
}

void withdraw(double amount)


throws InsufficientBalanceException {

if (amount > balance) {


throw new InsufficientBalanceException(
"Insufficient Account Balance"
);
}

balance -= amount;

[Link](
"Remaining Balance: Rs. "
+ balance
);
}
}

public class BankingApplication {


public static void main(String[] args) {
Account account =
new Account(50000);

try {
[Link](70000);
} catch (
InsufficientBalanceException e
) {
[Link]([Link]());
}
}
}

Concepts Learned

Custom exception, throw and throws.

38
HARD QUESTION 2 — STUDENT PERFORMANCE MANAGEMENT

Real-World Scenario

A college wants to dynamically maintain student records and identify students who scored 75 or above.

Question

Create a Student class. Store Student objects in an ArrayList and display students having marks greater than
or equal to 75.

Solution

import [Link];

class Student {
String usn;
String name;
int marks;

Student(
String usn,
String name,
int marks
) {
[Link] = usn;
[Link] = name;
[Link] = marks;
}
}

public class StudentManagement {


public static void main(String[] args) {
ArrayList<Student> students =
new ArrayList<>();

[Link](
new Student(
"1HK24CS001",
"Arun",
82
)
);

[Link](
new Student(

39
"1HK24CS002",
"Ayesha",
68
)
);

[Link](
new Student(
"1HK24CS003",
"Sneha",
91
)
);

for (Student student : students) {


if ([Link] >= 75) {
[Link](
[Link]
+ " "
+ [Link]
+ " "
+ [Link]
);
}
}
}
}

Concepts Learned

ArrayList of objects, dynamic object storage and object filtering.

FINAL 10-HOUR CORE JAVA TRAINING STRUCTURE


Session Duration Topic Key Skills

Session Fundamentals, Conditions and Variables, Scanner, if, switch, loops and
2 Hours
1 Loops business logic

Session Arrays, searching, String methods and


2 Hours Arrays and Strings
2 text processing

Session OOP – Classes, Objects and Classes, objects, constructors, this and
2 Hours
3 Constructors arrays of objects

40
Session Duration Topic Key Skills

Session OOP – Inheritance, Method extends, super, overriding, abstract


2 Hours
4 Overriding and Polymorphism classes and runtime polymorphism

Session Exception Handling and try-catch, throw, throws, custom


2 Hours
5 Collections exceptions, ArrayList and HashMap

TRAINING OUTCOME
At the end of the 10-hour Core Java training, students will be able to solve real-world computational
problems using Java fundamentals, process structured and textual data using arrays and strings, model
real-world entities using classes and objects, initialize and manage object state using constructors, design
reusable object-oriented systems using inheritance, method overriding and polymorphism, handle
application failures using Java exception handling, and manage dynamic application data using the Java
Collections Framework.

The training includes 30 real-world programming problems: 10 Easy, 10 Medium and 10 Hard problems,
progressing systematically from fundamental programming to object-oriented application development.

41

You might also like