Q1. Student Management System import java.util.Scanner; class Student { String name; int rollNumber; private double marks; void setMarks(double m) { marks = m; } double getMarks() { return marks; } String calculateGrade() { if (marks >= 90) return "A"; else if (marks >= 75) return "B"; else if (marks >= 60) return "C"; else return "F"; } } class GraduateStudent extends Student { String calculateGrade() { if (marks >= 85) return "A"; else if (marks >= 70) return "B"; else return "C"; } } public class Q1_StudentManagement { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Student s = new Student(); System.out.print("Enter student name: "); s.name = sc.nextLine(); System.out.print("Enter roll number: "); s.rollNumber = sc.nextInt(); System.out.print("Enter marks: "); s.setMarks(sc.nextDouble()); System.out.println("Name: " + s.name + ", Marks: " + s.getMarks() + ", Grade: " + s.calculateGrade()); GraduateStudent gs = new GraduateStudent(); sc.nextLine(); System.out.print("Enter graduate student name: "); gs.name = sc.nextLine(); System.out.print("Enter roll number: "); gs.rollNumber = sc.nextInt(); System.out.print("Enter marks: "); gs.setMarks(sc.nextDouble()); System.out.println("Name: " + gs.name + ", Marks: " + gs.getMarks() + ", Grade: " + gs.calculateGrade()); } } Q2. Bank Account System import java.util.Scanner; abstract class BankAccount { String holderName; int accountNumber; private double balance; BankAccount(String name, int acc, double bal) { holderName = name; accountNumber = acc; balance = bal; } void deposit(double amount) { balance += amount; System.out.println("Deposited: " + amount + " | Balance: " + balance); } abstract void withdraw(double amount); double getBalance() { return balance; } void setBalance(double b) { balance = b; } } class SavingsAccount extends BankAccount { SavingsAccount(String name, int acc, double bal) { super(name, acc, bal); } void withdraw(double amount) { if (getBalance() - amount < 500) System.out.println("Cannot withdraw. Minimum balance 500 required."); else { setBalance(getBalance() - amount); System.out.println("Withdrawn: " + amount + " | Balance: " + getBalance()); } } } public class Q2_BankAccount { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter holder name: "); String name = sc.nextLine(); System.out.print("Enter account number: "); int acc = sc.nextInt(); System.out.print("Enter initial balance: "); double bal = sc.nextDouble(); SavingsAccount sa = new SavingsAccount(name, acc, bal); System.out.print("Enter deposit amount: "); sa.deposit(sc.nextDouble()); System.out.print("Enter withdrawal amount: "); sa.withdraw(sc.nextDouble()); } } Q3. Employee Salary System import java.util.Scanner; class Employee { int empId; String name; private double salary; Employee(int id, String n, double s) { empId = id; name = n; salary = s; } void setSalary(double s) { salary = s; } double getSalary() { return salary; } void displaySalary() { System.out.println("Employee: " + name + " | Salary: " + salary); } double calculateBonus() { return salary * 0.10; } } class Manager extends Employee { Manager(int id, String n, double s) { super(id, n, s); } double calculateBonus() { return getSalary() * 0.20; } } public class Q3_EmployeeSalary { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter employee ID: "); int id = sc.nextInt(); sc.nextLine(); System.out.print("Enter employee name: "); String name = sc.nextLine(); System.out.print("Enter salary: "); double sal = sc.nextDouble(); Employee e = new Employee(id, name, sal); e.displaySalary(); System.out.println("Bonus: " + e.calculateBonus()); sc.nextLine(); System.out.print("Enter manager name: "); String mname = sc.nextLine(); System.out.print("Enter manager salary: "); double msal = sc.nextDouble(); Manager m = new Manager(id + 1, mname, msal); m.displaySalary(); System.out.println("Manager Bonus: " + m.calculateBonus()); } } Q4. Library Book Management import java.util.Scanner; abstract class Book { String bookName; String author; private double price; boolean isAvailable = true; Book(String n, String a, double p) { bookName = n; author = a; price = p; } double getPrice() { return price; } abstract void issueBook(); void returnBook() { isAvailable = true; System.out.println(bookName + " returned successfully."); } } class NormalBook extends Book { NormalBook(String n, String a, double p) { super(n, a, p); } void issueBook() { if (isAvailable) { isAvailable = false; System.out.println(bookName + " issued."); } else System.out.println(bookName + " not available."); } } class ReferenceBook extends Book { ReferenceBook(String n, String a, double p) { super(n, a, p); } void issueBook() { System.out.println(bookName + " is a reference book. Cannot be issued."); } } public class Q4_LibraryBook { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter book name: "); String name = sc.nextLine(); System.out.print("Enter author: "); String author = sc.nextLine(); System.out.print("Enter price: "); double price = sc.nextDouble(); NormalBook nb = new NormalBook(name, author, price); nb.issueBook(); nb.returnBook(); sc.nextLine(); System.out.print("Enter reference book name: "); String rname = sc.nextLine(); System.out.print("Enter author: "); String rauthor = sc.nextLine(); System.out.print("Enter price: "); double rprice = sc.nextDouble(); ReferenceBook rb = new ReferenceBook(rname, rauthor, rprice); rb.issueBook(); } } Q5. Shape Area Calculator import java.util.Scanner; class Shape { double calculateArea() { return 0; } } class Circle extends Shape { double radius; Circle(double r) { radius = r; } double calculateArea() { return 3.14 * radius * radius; } } class Rectangle extends Shape { double length, width; Rectangle(double l, double w) { length = l; width = w; } double calculateArea() { return length * width; } } class Triangle extends Shape { double base, height; Triangle(double b, double h) { base = b; height = h; } double calculateArea() { return 0.5 * base * height; } } public class Q5_ShapeArea { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter circle radius: "); Circle c = new Circle(sc.nextDouble()); System.out.print("Enter rectangle length: "); double l = sc.nextDouble(); System.out.print("Enter rectangle width: "); Rectangle r = new Rectangle(l, sc.nextDouble()); System.out.print("Enter triangle base: "); double b = sc.nextDouble(); System.out.print("Enter triangle height: "); Triangle t = new Triangle(b, sc.nextDouble()); System.out.println("Circle Area: " + c.calculateArea()); System.out.println("Rectangle Area: " + r.calculateArea()); System.out.println("Triangle Area: " + t.calculateArea()); } } Q6. Vehicle Information System import java.util.Scanner; class Vehicle { String modelName; private int speed; Vehicle(String m, int s) { modelName = m; speed = s; } void setSpeed(int s) { speed = s; } int getSpeed() { return speed; } void start() { System.out.println(modelName + " started."); } void stop() { System.out.println(modelName + " stopped."); } void display() { System.out.println("Model: " + modelName + " | Speed: " + speed); } } class Car extends Vehicle { String brand; Car(String m, int s, String b) { super(m, s); brand = b; } void display() { System.out.println("Car | Brand: " + brand + " | Model: " + modelName + " | Speed: " + getSpeed()); } } class Bike extends Vehicle { String type; Bike(String m, int s, String t) { super(m, s); type = t; } void display() { System.out.println("Bike | Type: " + type + " | Model: " + modelName + " | Speed: " + getSpeed()); } } public class Q6_VehicleInfo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter car brand: "); String brand = sc.nextLine(); System.out.print("Enter car model: "); String cmodel = sc.nextLine(); System.out.print("Enter car speed: "); int cspeed = sc.nextInt(); Car car = new Car(cmodel, cspeed, brand); car.start(); car.display(); car.stop(); sc.nextLine(); System.out.print("Enter bike type: "); String btype = sc.nextLine(); System.out.print("Enter bike model: "); String bmodel = sc.nextLine(); System.out.print("Enter bike speed: "); int bspeed = sc.nextInt(); Bike bike = new Bike(bmodel, bspeed, btype); bike.start(); bike.display(); bike.stop(); } } Q7. Hospital Patient Record System import java.util.Scanner; class Patient { int patientId; String name; String disease; private String medicalReport; Patient(int id, String n, String d, String r) { patientId = id; name = n; disease = d; medicalReport = r; } void updateReport(String r) { medicalReport = r; } void displayDetails() { System.out.println("ID: " + patientId + " | Name: " + name + " | Disease: " + disease); } void treatmentPriority() { System.out.println("Normal priority treatment."); } } class EmergencyPatient extends Patient { EmergencyPatient(int id, String n, String d, String r) { super(id, n, d, r); } void treatmentPriority() { System.out.println("URGENT! Immediate treatment required."); } } public class Q7_HospitalRecord { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter patient ID: "); int id = sc.nextInt(); sc.nextLine(); System.out.print("Enter name: "); String name = sc.nextLine(); System.out.print("Enter disease: "); String disease = sc.nextLine(); Patient p = new Patient(id, name, disease, "General Report"); p.displayDetails(); p.treatmentPriority(); System.out.print("Enter emergency patient name: "); String ename = sc.nextLine(); System.out.print("Enter disease: "); String edisease = sc.nextLine(); EmergencyPatient ep = new EmergencyPatient(id + 1, ename, edisease, "Emergency Report"); ep.displayDetails(); ep.treatmentPriority(); } } Q8. Online Shopping Cart import java.util.Scanner; class Product { String productName; private double price; int quantity; Product(String n, double p, int q) { productName = n; price = p; quantity = q; } double getPrice() { return price; } void addProduct(int qty) { quantity += qty; System.out.println(qty + " items added."); } void removeProduct(int qty) { if (qty > quantity) System.out.println("Not enough stock."); else { quantity -= qty; System.out.println(qty + " items removed."); } } double totalBill() { return price * quantity; } } class DiscountProduct extends Product { double discount; DiscountProduct(String n, double p, int q, double d) { super(n, p, q); discount = d; } double totalBill() { double bill = getPrice() * quantity; return bill - (bill * discount / 100); } } public class Q8_ShoppingCart { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter product name: "); String name = sc.nextLine(); System.out.print("Enter price: "); double price = sc.nextDouble(); System.out.print("Enter quantity: "); int qty = sc.nextInt(); Product p = new Product(name, price, qty); System.out.print("Add how many items: "); p.addProduct(sc.nextInt()); System.out.println("Total Bill: " + p.totalBill()); sc.nextLine(); System.out.print("Enter discount product name: "); String dname = sc.nextLine(); System.out.print("Enter price: "); double dprice = sc.nextDouble(); System.out.print("Enter quantity: "); int dqty = sc.nextInt(); System.out.print("Enter discount (%): "); double disc = sc.nextDouble(); DiscountProduct dp = new DiscountProduct(dname, dprice, dqty, disc); System.out.println("Discounted Bill: " + dp.totalBill()); } } Q9. Mobile Recharge System import java.util.Scanner; class RechargePlan { String planName; int validity; private double amount; RechargePlan(String n, int v, double a) { planName = n; validity = v; amount = a; } double getAmount() { return amount; } void displayPlan() { System.out.println("Plan: " + planName + " | Validity: " + validity + " days | Amount: Rs." + amount); } void rechargeBenefits() { System.out.println("Benefits: Unlimited calls + 1GB/day data."); } } class SpecialPlan extends RechargePlan { String extraBenefit; SpecialPlan(String n, int v, double a, String e) { super(n, v, a); extraBenefit = e; } void rechargeBenefits() { System.out.println("Benefits: Unlimited calls + 2GB/day + " + extraBenefit); } } public class Q9_MobileRecharge { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter plan name: "); String name = sc.nextLine(); System.out.print("Enter validity (days): "); int val = sc.nextInt(); System.out.print("Enter amount: "); double amt = sc.nextDouble(); sc.nextLine(); RechargePlan rp = new RechargePlan(name, val, amt); rp.displayPlan(); rp.rechargeBenefits(); System.out.print("Enter special plan name: "); String sname = sc.nextLine(); System.out.print("Enter validity (days): "); int sval = sc.nextInt(); System.out.print("Enter amount: "); double samt = sc.nextDouble(); sc.nextLine(); System.out.print("Enter extra benefit: "); String extra = sc.nextLine(); SpecialPlan sp = new SpecialPlan(sname, sval, samt, extra); sp.displayPlan(); sp.rechargeBenefits(); } } Q10. College Course Registration import java.util.Scanner; class Course { String courseName; String code; private double fees; int studentCount = 0; Course(String n, String c, double f) { courseName = n; code = c; fees = f; } double getFees() { return fees; } void registerStudent(String studentName) { studentCount++; System.out.println(studentName + " registered in " + courseName + ". Total students: " + studentCount); } double calculateFees() { return fees; } } class OnlineCourse extends Course { double discount; OnlineCourse(String n, String c, double f, double d) { super(n, c, f); discount = d; } double calculateFees() { return getFees() - (getFees() * discount / 100); } } public class Q10_CourseRegistration { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter course name: "); String cname = sc.nextLine(); System.out.print("Enter course code: "); String code = sc.nextLine(); System.out.print("Enter fees: "); double fees = sc.nextDouble(); sc.nextLine(); Course c = new Course(cname, code, fees); System.out.print("Enter student name to register: "); c.registerStudent(sc.nextLine()); System.out.println("Fees: Rs." + c.calculateFees()); System.out.print("Enter online course name: "); String ocname = sc.nextLine(); System.out.print("Enter course code: "); String ocode = sc.nextLine(); System.out.print("Enter fees: "); double ofees = sc.nextDouble(); System.out.print("Enter discount (%): "); double disc = sc.nextDouble(); sc.nextLine(); OnlineCourse oc = new OnlineCourse(ocname, ocode, ofees, disc); System.out.print("Enter student name to register: "); oc.registerStudent(sc.nextLine()); System.out.println("Online Fees (after discount): Rs." + oc.calculateFees()); } } Q11. Inheritance - Vehicle and Car import java.util.Scanner; class Vehicle { int speed; String fuelType; Vehicle(int s, String f) { speed = s; fuelType = f; } void displayDetails() { System.out.println("Speed: " + speed + " | Fuel: " + fuelType); } } class Car extends Vehicle { String brand; Car(int s, String f, String b) { super(s, f); brand = b; } void displayDetails() { System.out.println("Brand: " + brand + " | Speed: " + speed + " | Fuel: " + fuelType); } } public class Q11_Inheritance { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter car brand: "); String brand = sc.nextLine(); System.out.print("Enter speed: "); int speed = sc.nextInt(); sc.nextLine(); System.out.print("Enter fuel type: "); String fuel = sc.nextLine(); Car c = new Car(speed, fuel, brand); c.displayDetails(); } } Q12. Method Overriding - Animal Sounds import java.util.Scanner; class Animal { void makeSound() { System.out.println("Animal makes a sound."); } } class Dog extends Animal { void makeSound() { System.out.println("Dog says: Woof!"); } } class Cat extends Animal { void makeSound() { System.out.println("Cat says: Meow!"); } } public class Q12_MethodOverriding { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Choose animal: 1. Dog 2. Cat"); System.out.print("Enter choice: "); int choice = sc.nextInt(); Animal a; if (choice == 1) a = new Dog(); else a = new Cat(); a.makeSound(); } } Q13. super Keyword import java.util.Scanner; class Person { String name; int age; Person(String n, int a) { name = n; age = a; } } class Student extends Person { int rollNumber; Student(String n, int a, int r) { super(n, a); rollNumber = r; } void display() { System.out.println("Name: " + name + " | Age: " + age + " | Roll No: " + rollNumber); } } public class Q13_SuperKeyword { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter name: "); String name = sc.nextLine(); System.out.print("Enter age: "); int age = sc.nextInt(); System.out.print("Enter roll number: "); int roll = sc.nextInt(); Student s = new Student(name, age, roll); s.display(); } } Q14. Abstract Classes import java.util.Scanner; abstract class Shape { abstract double calculateArea(); void displayShapeType() { System.out.println("This is a shape."); } } class Circle extends Shape { double radius; Circle(double r) { radius = r; } double calculateArea() { return 3.14 * radius * radius; } } class Rectangle extends Shape { double length, width; Rectangle(double l, double w) { length = l; width = w; } double calculateArea() { return length * width; } } public class Q14_AbstractClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter circle radius: "); Circle c = new Circle(sc.nextDouble()); c.displayShapeType(); System.out.println("Circle Area: " + c.calculateArea()); System.out.print("Enter rectangle length: "); double l = sc.nextDouble(); System.out.print("Enter rectangle width: "); Rectangle r = new Rectangle(l, sc.nextDouble()); r.displayShapeType(); System.out.println("Rectangle Area: " + r.calculateArea()); } } Q15. Interfaces - Playable import java.util.Scanner; interface Playable { void play(); void pause(); } class MusicPlayer implements Playable { public void play() { System.out.println("Music is playing."); } public void pause() { System.out.println("Music is paused."); } } class VideoPlayer implements Playable { public void play() { System.out.println("Video is playing."); } public void pause() { System.out.println("Video is paused."); } } public class Q15_Interface { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Choose player: 1. Music 2. Video"); System.out.print("Enter choice: "); int choice = sc.nextInt(); Playable p; if (choice == 1) p = new MusicPlayer(); else p = new VideoPlayer(); p.play(); p.pause(); } } Q16. Multiple Inheritance via Interfaces import java.util.Scanner; interface Camera { void takePhoto(); } interface GPS { void navigate(); } class SmartPhone implements Camera, GPS { String brand; SmartPhone(String b) { brand = b; } public void takePhoto() { System.out.println(brand + ": Photo taken."); } public void navigate() { System.out.println(brand + ": Navigating to destination."); } } public class Q16_MultipleInterface { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter smartphone brand: "); String brand = sc.nextLine(); SmartPhone sp = new SmartPhone(brand); sp.takePhoto(); sp.navigate(); } } Q17. Package Program /* FOLDER STRUCTURE: com/library/books/Book.java MainClass.java -- FILE: com/library/books/Book.java -- package com.library.books; public class Book { public String title; public String author; public Book(String t, String a) { title = t; author = a; } public void display() { System.out.println("Title: " + title + " | Author: " + author); } } -- FILE: MainClass.java -- */ import com.library.books.Book; import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter book title: "); String title = sc.nextLine(); System.out.print("Enter author name: "); String author = sc.nextLine(); Book b = new Book(title, author); b.display(); } } /* COMPILE & RUN: javac com/library/books/Book.java javac MainClass.java java MainClass */ Q18. Single Inheritance import java.util.Scanner; class Person { String name; int age; void displayPerson() { System.out.println("Name: " + name + " | Age: " + age); } } class Employee extends Person { double salary; void displayEmployee() { System.out.println("Salary: Rs." + salary); } } public class Q18_SingleInheritance { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter name: "); String name = sc.nextLine(); System.out.print("Enter age: "); int age = sc.nextInt(); System.out.print("Enter salary: "); double salary = sc.nextDouble(); Employee e = new Employee(); e.name = name; e.age = age; e.salary = salary; e.displayPerson(); e.displayEmployee(); } } Q19. Interface - Bank import java.util.Scanner; interface Bank { void deposit(double amount); void withdraw(double amount); } class CustomerAccount implements Bank { double balance; String accountHolder; CustomerAccount(String name, double bal) { accountHolder = name; balance = bal; } public void deposit(double amount) { balance += amount; System.out.println("Deposited Rs." + amount + " | New Balance: Rs." + balance); } public void withdraw(double amount) { if (amount > balance) System.out.println("Insufficient balance."); else { balance -= amount; System.out.println("Withdrawn Rs." + amount + " | New Balance: Rs." + balance); } } } public class Q19_BankInterface { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter account holder name: "); String name = sc.nextLine(); System.out.print("Enter initial balance: "); double bal = sc.nextDouble(); CustomerAccount ca = new CustomerAccount(name, bal); System.out.print("Enter deposit amount: "); ca.deposit(sc.nextDouble()); System.out.print("Enter withdrawal amount: "); ca.withdraw(sc.nextDouble()); } } Q20. Method Overriding - Shape Draw import java.util.Scanner; class Shape { void draw() { System.out.println("Drawing a shape."); } } class Circle extends Shape { void draw() { System.out.println("Drawing a Circle."); } } class Square extends Shape { void draw() { System.out.println("Drawing a Square."); } } public class Q20_DrawShapes { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Choose shape: 1. Circle 2. Square"); System.out.print("Enter choice: "); int choice = sc.nextInt(); Shape s; if (choice == 1) s = new Circle(); else s = new Square(); s.draw(); } } Q21. Bank Withdrawal with Exception and Thread import java.util.Scanner; class InsufficientBalanceException extends Exception { InsufficientBalanceException(String msg) { super(msg); } } class TransactionHistory extends Thread { double amount; TransactionHistory(double a) { amount = a; } public void run() { System.out.println("Transaction history: Withdrawal of Rs." + amount + " attempted."); } } public class Q21_BankWithdrawal { static void withdraw(double balance, double amount) throws InsufficientBalanceException { if (amount > balance) throw new InsufficientBalanceException("Insufficient balance!"); System.out.println("Withdrawal successful. Remaining: Rs." + (balance - amount)); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter account balance: "); double balance = sc.nextDouble(); System.out.print("Enter withdrawal amount: "); double amount = sc.nextDouble(); try { withdraw(balance, amount); } catch (InsufficientBalanceException e) { System.out.println("Error: " + e.getMessage()); } finally { System.out.println("Transaction process complete."); } new TransactionHistory(amount).start(); } } Q22. Student Marks Processing with Thread import java.util.Scanner; class PercentageCalculator implements Runnable { int[] marks; PercentageCalculator(int[] m) { marks = m; } public void run() { int total = 0; for (int m : marks) total += m; System.out.println("Total: " + total + " | Percentage: " + (total / 5.0) + "%"); } } public class Q22_StudentMarks { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] marks = new int[5]; try { for (int i = 0; i < 5; i++) { System.out.print("Enter marks for subject " + (i + 1) + ": "); marks[i] = sc.nextInt(); if (marks[i] < 0 || marks[i] > 100) throw new Exception("Invalid marks: " + marks[i] + ". Must be 0-100."); } } catch (Exception e) { System.out.println("Error: " + e.getMessage()); return; } new Thread(new PercentageCalculator(marks)).start(); } } Q23. Railway Reservation System import java.util.Scanner; class SeatNotAvailableException extends Exception { SeatNotAvailableException(String msg) { super(msg); } } class BookingConfirmation extends Thread { int seats; String passengerName; BookingConfirmation(int s, String n) { seats = s; passengerName = n; } public void run() { System.out.println("Booking confirmed for " + passengerName + " | Seats: " + seats); } } public class Q23_RailwayReservation { static int availableSeats = 10; static void bookSeats(int seats) throws SeatNotAvailableException { if (seats > availableSeats) throw new SeatNotAvailableException("Only " + availableSeats + " seats available."); availableSeats -= seats; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter passenger name: "); String name = sc.nextLine(); System.out.print("Enter number of seats: "); int seats = sc.nextInt(); try { bookSeats(seats); System.out.println("Seats booked. Remaining seats: " + availableSeats); new BookingConfirmation(seats, name).start(); } catch (SeatNotAvailableException e) { System.out.println("Error: " + e.getMessage()); } } } Q24. ATM Login System import java.util.Scanner; class InvalidPinException extends Exception { InvalidPinException(String msg) { super(msg); } } class LoginThread extends Thread { String user; LoginThread(String u) { user = u; } public void run() { System.out.println("Login check: User '" + user + "' verified."); } } class TransactionThread extends Thread { public void run() { System.out.println("Transaction processing started..."); } } public class Q24_ATMLogin { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int correctPin = 1234; System.out.print("Enter account holder name: "); String user = sc.nextLine(); System.out.print("Enter ATM PIN: "); int pin = sc.nextInt(); try { if (pin != correctPin) throw new InvalidPinException("Incorrect PIN entered!"); System.out.println("Login successful. Welcome " + user); new LoginThread(user).start(); new TransactionThread().start(); } catch (InvalidPinException e) { System.out.println("Error: " + e.getMessage()); } finally { System.out.println("Session closed."); } } } Q25. Voting Eligibility Checker import java.util.Scanner; class UnderAgeException extends Exception { UnderAgeException(String msg) { super(msg); } } class VoterVerification extends Thread { String name; VoterVerification(String n) { name = n; } public void run() { System.out.println("Voter verification complete for: " + name); } } public class Q25_VotingEligibility { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter your name: "); String name = sc.nextLine(); System.out.print("Enter your age: "); int age = sc.nextInt(); try { if (age < 0) throw new ArithmeticException("Age cannot be negative."); if (age < 18) throw new UnderAgeException("You are underage. Minimum age to vote is 18."); System.out.println(name + " is eligible to vote."); new VoterVerification(name).start(); } catch (UnderAgeException e) { System.out.println("Error: " + e.getMessage()); } catch (ArithmeticException e) { System.out.println("Error: " + e.getMessage()); } } } Q26. Online Payment System import java.util.Scanner; class PaymentFailedException extends Exception { PaymentFailedException(String msg) { super(msg); } } class PaymentConfirmation implements Runnable { double amount; PaymentConfirmation(double a) { amount = a; } public void run() { System.out.println("Payment confirmation: Rs." + amount + " paid successfully."); } } public class Q26_OnlinePayment { static void processPayment(double amount) throws PaymentFailedException { if (amount <= 0) throw new PaymentFailedException("Invalid payment amount. Must be greater than 0."); System.out.println("Payment of Rs." + amount + " processed."); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter payment amount: "); double amount = sc.nextDouble(); try { processPayment(amount); } catch (PaymentFailedException e) { System.out.println("Error: " + e.getMessage()); } finally { System.out.println("Payment session ended."); } new Thread(new PaymentConfirmation(amount)).start(); } } Q27. Employee Salary Management import java.util.Scanner; class InvalidSalaryException extends Exception { InvalidSalaryException(String msg) { super(msg); } } class SalarySlip extends Thread { String name; double salary; SalarySlip(String n, double s) { name = n; salary = s; } public void run() { System.out.println("------ Salary Slip ------"); System.out.println("Employee: " + name + " | Salary: Rs." + salary); System.out.println("-------------------------"); } } public class Q27_EmployeeSalaryMgmt { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter employee name: "); String name = sc.nextLine(); System.out.print("Enter employee ID: "); int id = sc.nextInt(); System.out.print("Enter salary: "); double salary = sc.nextDouble(); try { if (salary < 0) throw new InvalidSalaryException("Salary cannot be negative."); System.out.println("Salary for ID " + id + " updated successfully."); new SalarySlip(name, salary).start(); } catch (InvalidSalaryException e) { System.out.println("Error: " + e.getMessage()); } catch (Exception e) { System.out.println("Unexpected error: " + e.getMessage()); } } } Q28. Library Fine System import java.util.Scanner; class FineCalculator extends Thread { String borrowerName; int days; FineCalculator(String n, int d) { borrowerName = n; days = d; } public void run() { double fine = days * 2.0; System.out.println("Borrower: " + borrowerName); System.out.println("Late Days: " + days + " | Fine: Rs." + fine); System.out.println("Receipt generated."); } } public class Q28_LibraryFine { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter borrower name: "); String name = sc.nextLine(); System.out.print("Enter number of late days: "); int days = sc.nextInt(); try { if (days < 0) throw new Exception("Invalid number of days. Cannot be negative."); new FineCalculator(name, days).start(); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } finally { System.out.println("Fine system process complete."); } } } Q29. Hospital Appointment System import java.util.Scanner; class SlotUnavailableException extends Exception { SlotUnavailableException(String msg) { super(msg); } } class AppointmentConfirmation extends Thread { String patientName; int slot; AppointmentConfirmation(String n, int s) { patientName = n; slot = s; } public void run() { System.out.println("Appointment confirmed for " + patientName + " at slot " + slot + "."); } } public class Q29_HospitalAppointment { static int availableSlot = 3;