0% found this document useful (0 votes)
4 views56 pages

Java Internal1

Uploaded by

Siddu Yaghna
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)
4 views56 pages

Java Internal1

Uploaded by

Siddu Yaghna
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

Set-2

[Link] Marks Storage and Average Calculation using Two-Dimensional Array

import [Link];

public class StudentMarks {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

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

int students = [Link]();

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

int subjects = [Link]();

int[][] marks = new int[students][subjects];

double[] average = new double[students];

for (int i = 0; i < students; i++) {

[Link]("Enter marks for Student " + (i + 1) + ":");

int sum = 0;

for (int j = 0; j < subjects; j++) {

[Link]("Subject " + (j + 1) + ": ");

marks[i][j] = [Link]();

sum += marks[i][j];

average[i] = (double) sum / subjects;}

[Link]("------Student Performance Summary -------");

for (int i = 0; i < students; i++) {

[Link]("Student " + (i + 1) + " Marks: ");

for (int j = 0; j < subjects; j++) {

[Link](marks[i][j] + " "); }

[Link]("|Average: %.2f%n", average[i]); } }

}
2: Online Payment Processing using Lambda Expressions.

import [Link];

@FunctionalInterface

interface PaymentMethod {

double calculate(double amount);

public class PaymentProcessing {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

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

double amount = [Link]();

PaymentMethod creditCard = (amt) -> amt + (amt * 0.02);

PaymentMethod upi = (amt) -> amt + 5;

PaymentMethod cod = (amt) -> amt + 30;

[Link]("\n------- Estimated Payable Amount -------");

[Link]("Via Credit Card Amount to be paid = Rs." +


[Link](amount));

[Link]("Via UPI Amount to be paid = Rs." + [Link](amount));

[Link]("Via Cash on Delivery Amount to be paid = Rs." +


[Link](amount));

Task 1:
[Link] and Currency Conversion System

import [Link];

public class BillingSystem {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);


[Link]("Enter Quantity (byte): ");

byte quantity = [Link]();

[Link]("Enter Unit Price (int): ");

int unitPrice = [Link]();

[Link]("Enter Tax Rate (in decimal, e.g., 0.18 for 18%): ");

float taxRate = [Link]();

int baseAmount = quantity * unitPrice;

float taxAmount = baseAmount * taxRate; // implicit type promotion: int → float

double totalAmount = baseAmount + taxAmount; // implicit promotion: float →


double

[Link]("\n----------- Billing Summary -----------");

[Link]("Quantity (byte): " + quantity);

[Link]("Unit Price (int): Rs." + unitPrice);

[Link]("Base Amount (int): Rs." + baseAmount);

[Link]("Tax Rate (float): " + taxRate);

[Link]("Tax Amount (float): Rs." + taxAmount);

[Link]("Total Amount to Pay (double): Rs." + totalAmount);

[Link]("\nEnter Payment in USD for the above total: ");

double usdPayment = [Link]();

[Link]("Enter USD to INR Conversion Rate (float): ");

float conversionRate = [Link]();

float convertedINR = (float) (usdPayment * conversionRate);

[Link]("\n----------- USD to INR Conversion -----------");

[Link]("Amount Paid in USD: $" + usdPayment);

[Link]("Conversion Rate: " + conversionRate);

[Link]("Converted Amount in INR: Rs." + convertedINR);

if (convertedINR >= totalAmount) {


[Link]("Payment is sufficient.");

[Link]("Change to return: Rs.%.2f%n", (convertedINR - totalAmount));

} else {

[Link]("Payment is insufficient.");

[Link]("Remaining amount to be paid: Rs.%.2f%n", (totalAmount -


convertedINR));

2. Warehouse Inventory Management using Java Packages

[Link]

(Package: [Link])

package [Link];

public class Product {

private int productId;

private String name;

private String category;

public Product(int productId, String name, String category) {

[Link] = productId;

[Link] = name;

[Link] = category;

public int getProductId() {

return productId;

public String getName() {

return name;

}
public String getCategory() {

return category;

🧩 File 2: [Link]

(Package: [Link])

package [Link];

import [Link];

public class Stock extends Product {

private int quantity;

private double unitPrice;

public Stock(int productId, String name, String category, int quantity, double unitPrice) {

super(productId, name, category);

[Link] = quantity;

[Link] = unitPrice;

public int getQuantity() {

return quantity;

public double getUnitPrice() {

return unitPrice;

public double calculateTotalValue() {

return quantity * unitPrice;

}
🧩 File 3: [Link]

(Package: [Link])

package [Link];

import [Link];

public class ReportGenerator {

public void printProductReport(Stock stock) {

[Link]("-------- Inventory Report --------");

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

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

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

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

[Link]("Unit Price : Rs." + [Link]());

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

[Link]("------------------------------------");

public void printSummary(Stock[] stocks) {

[Link]("========= Final Inventory Summary =========");

double grandTotal = 0;

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

Stock s = stocks[i];

double totalValue = [Link]();

[Link]("Product " + (i + 1));

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

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

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

[Link]("Total Value: Rs.%.2f%n", totalValue);

grandTotal += totalValue;
}

[Link]("\nGrand Total Inventory Value: Rs.%.2f%n", grandTotal);

[Link]("-------------------------------------------------");

🧩 File 4: [Link]

(Package: mainapp)

package mainapp;

import [Link];

import [Link];

import [Link];

public class WareHouse {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

ReportGenerator report = new ReportGenerator();

[Link]("Enter number of products to add: ");

int n = [Link]();

[Link](); // consume newline

Stock[] products = new Stock[n];

for (int i = 0; i < n; i++) {

[Link]("---- Enter details for Product " + (i + 1) + " ----");

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

int id = [Link]();

[Link](); // consume newline

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

String name = [Link]();

[Link]("Enter Category: ");


String category = [Link]();

[Link]("Enter Quantity: ");

int qty = [Link]();

[Link]("Enter Unit Price: Rs.");

double price = [Link]();

products[i] = new Stock(id, name, category, qty, price);

[Link](products[i]);

[Link](products);

[Link]();

Task-3:
1. Book Information Management System

File 1: [Link]

public class Book {

private String bookName;

private String isbn;

private String author;

private String publisher;

// Constructor

public Book(String bookName, String isbn, String author, String publisher) {

[Link] = bookName;

[Link] = isbn;

[Link] = author;

[Link] = publisher;

}
// Mutator (Setter) Methods

public void setBookName(String bookName) {

[Link] = bookName;

public void setIsbn(String isbn) {

[Link] = isbn;

public void setAuthor(String author) {

[Link] = author;

public void setPublisher(String publisher) {

[Link] = publisher;

// Accessor (Getter) Methods

public String getBookName() {

return [Link];

public String getIsbn() {

return [Link];

public String getAuthor() {

return [Link];

public String getPublisher() {

return [Link];

}
// Method to return complete book info

public String getBookInfo() {

return "Book Name: " + [Link] + "\n" +

"ISBN: " + [Link] + "\n" +

"Author: " + [Link] + "\n" +

"Publisher: " + [Link];

📗 File 2: [Link]

import [Link];

public class BookTest {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

Book[] books = new Book[30];

[Link]("Enter number of books to input (up to 30): ");

int n = [Link]();

[Link](); // consume newline

for (int i = 0; i < n; i++) {

[Link]("\nEnter details for Book " + (i + 1));

[Link]("Enter Book Name: ");

String name = [Link]();

[Link]("Enter ISBN Number: ");

String isbn = [Link]();

[Link]("Enter Author Name: ");


String author = [Link]();

[Link]("Enter Publisher: ");

String publisher = [Link]();

books[i] = new Book(name, isbn, author, publisher);

[Link]("\n--- Book Details ---");

for (int i = 0; i < n; i++) {

[Link]("Book " + (i + 1) + " Info:");

[Link](books[i].getBookInfo());

[Link]();

[Link]();

2. Ride-Sharing Fare Calculation using Lambda Expressions as Arguments

import [Link];

@FunctionalInterface

interface FareStrategy {

double calculateFare(double distance);

public class RideSharingFare {

public static void printFare(String rideType, FareStrategy strategy, double distance) {

double fare = [Link](distance);

[Link](rideType + " Fare: Rs." + fare);

}
public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

[Link]("Enter distance traveled (in km): ");

double distance = [Link]();

FareStrategy standardRide = (d) -> 50 + (10 * d);

FareStrategy premiumRide = (d) -> 100 + (20 * d);

FareStrategy sharedRide = (d) -> 30 + (8 * d);

[Link]("\n------ Fare Calculation Summary ------");

printFare("Standard Ride", standardRide, distance);

printFare("Premium Ride", premiumRide, distance);

printFare("Shared Ride", sharedRide, distance);

[Link]();

Task-4

1. Development of a Console-Based Text Editing Tool Using Java StringBuffer

import [Link];

public class TextEditor {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

[Link]("Enter initial text: ");

StringBuffer textBuffer = new StringBuffer([Link]());

[Link]("Current Text: " + textBuffer);

while (true) {

[Link]("\nChoose an operation:");

[Link]("1. Append text");


[Link]("2. Insert text");

[Link]("3. Replace text");

[Link]("4. Delete text");

[Link]("5. Reverse text");

[Link]("6. Set specific character");

[Link]("7. Set length");

[Link]("8. Show char at index");

[Link]("9. Show capacity & length");

[Link]("10. Exit");

[Link]("Enter your choice (1-10): ");

int choice = [Link]();

[Link](); // Clear input buffer

switch (choice) {

case 1: // Append

[Link]("Enter text to append: ");

String appendText = [Link]();

[Link](appendText);

break;

case 2: // Insert

[Link]("Enter position to insert at: ");

int insertPos = [Link]();

[Link]();

[Link]("Enter text to insert: ");

String insertText = [Link]();

if (insertPos >= 0 && insertPos <= [Link]())

[Link](insertPos, insertText);

else

[Link]("Invalid position!");
break;

case 3: // Replace

[Link]("Enter start index: ");

int start = [Link]();

[Link]("Enter end index: ");

int end = [Link]();

[Link]();

[Link]("Enter replacement text: ");

String replaceText = [Link]();

if (start >= 0 && end <= [Link]() && start < end)

[Link](start, end, replaceText);

else

[Link]("Invalid range!");

break;

case 4: // Delete

[Link]("Enter start index: ");

int delStart = [Link]();

[Link]("Enter end index: ");

int delEnd = [Link]();

[Link]();

if (delStart >= 0 && delEnd <= [Link]() && delStart < delEnd)

[Link](delStart, delEnd);

else

[Link]("Invalid range!");

break;

case 5: // Reverse

[Link]();
break;

case 6: // Set specific character

[Link]("Enter index to modify: ");

int index = [Link]();

[Link]();

[Link]("Enter new character: ");

char ch = [Link]().charAt(0);

if (index >= 0 && index < [Link]())

[Link](index, ch);

else

[Link]("Invalid index!");

break;

case 7: // Set length

[Link]("Enter new length: ");

int newLength = [Link]();

[Link]();

[Link](newLength);

break;

case 8: // Show char at index

[Link]("Enter index to view character: ");

int viewIndex = [Link]();

[Link]();

if (viewIndex >= 0 && viewIndex < [Link]())

[Link]("Character at index " + viewIndex + ": " +


[Link](viewIndex));

else

[Link]("Invalid index!");

break;
case 9: // Capacity & length

[Link]("Current Capacity: " + [Link]());

[Link]("Current Length: " + [Link]());

break;

case 10:

[Link]("Exiting editor. Goodbye!");

[Link]();

return;

default:

[Link]("Invalid choice! Please enter 1–10.");

[Link]("\nCurrent Text: " + textBuffer);

2. [Link]

class PrintJob extends Thread {

private String jobType;

// Constructor

public PrintJob(String jobType) {

[Link] = jobType;

// Run method (executed when thread starts)

@Override

public void run() {

for (int i = 1; i <= 5; i++) {


[Link](jobType + " - Page " + i + " by " +
[Link]().getName());

try {

[Link](100); // Simulate printing time

} catch (InterruptedException e) {

[Link](jobType + " interrupted.");

public class PrintJobScheduling {

public static void main(String[] args) {

// Creating threads for each job type

PrintJob urgentJob = new PrintJob("Urgent print job");

PrintJob regularJob = new PrintJob("Regular print job");

PrintJob bulkJob = new PrintJob("Bulk print job");

// Setting thread priorities

[Link](Thread.MAX_PRIORITY); // Highest priority (10)

[Link](Thread.NORM_PRIORITY); // Normal priority (5)

[Link](Thread.MIN_PRIORITY); // Lowest priority (1)

// Start threads

[Link]();

[Link]();

[Link]();

}
Task-5:

1. University Staff Management System

import [Link];

// Base class - common for all staff

class Staff {

String name;

int staffID;

double baseSalary;

// Constructor

Staff(String name, int staffID, double baseSalary) {

[Link] = name;

[Link] = staffID;

[Link] = baseSalary;

// Display method

void displayDetails() {

[Link]("Name : " + name);

[Link]("Staff ID : " + staffID);

[Link]("Base Salary: " + baseSalary);

// Derived class (Single Inheritance)

class TeachingStaff extends Staff {

String subject;

int experience;
TeachingStaff(String name, int staffID, double baseSalary, String subject, int experience)
{

super(name, staffID, baseSalary); // Call parent constructor

[Link] = subject;

[Link] = experience;

void displayTeachingDetails() {

[Link]("\n--- Teaching Staff Details ---");

[Link](); // Call parent class method

[Link]("Subject : " + subject);

[Link]("Experience : " + experience + " years");

// Multilevel inheritance: HOD extends TeachingStaff

class HOD extends TeachingStaff {

String department;

HOD(String name, int staffID, double baseSalary, String subject, int experience, String
department) {

super(name, staffID, baseSalary, subject, experience);

[Link] = department;

void displayHODDetails() {

[Link]("\n--- HOD Details ---");

[Link]();
[Link]("Subject : " + subject);

[Link]("Experience : " + experience + " years");

[Link]("Department : " + department);

// Hierarchical inheritance: another subclass of Staff

class NonTeachingStaff extends Staff {

String role;

NonTeachingStaff(String name, int staffID, double baseSalary, String role) {

super(name, staffID, baseSalary);

[Link] = role;

void displayNonTeachingDetails() {

[Link]("\n--- Non-Teaching Staff Details ---");

[Link]();

[Link]("Role : " + role);

public class UniversityStaffManagement {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

[Link]("-------- University Staff Record --------");

[Link]("1. Teaching Staff");


[Link]("2. HOD");

[Link]("3. Non-Teaching Staff");

[Link]("Enter your choice: ");

int choice = [Link]();

[Link](); // consume newline

switch (choice) {

case 1:

[Link]("Enter Name: ");

String tName = [Link]();

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

int tID = [Link]();

[Link]("Enter Base Salary: ");

double tSalary = [Link]();

[Link]();

[Link]("Enter Subject: ");

String subject = [Link]();

[Link]("Enter Experience (in years): ");

int exp = [Link]();

TeachingStaff ts = new TeachingStaff(tName, tID, tSalary, subject, exp);

[Link]();

break;

case 2:

[Link]("Enter Name: ");

String hName = [Link]();

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


int hID = [Link]();

[Link]("Enter Base Salary: ");

double hSalary = [Link]();

[Link]();

[Link]("Enter Subject: ");

String hSubject = [Link]();

[Link]("Enter Experience (in years): ");

int hExp = [Link]();

[Link]();

[Link]("Enter Department: ");

String dept = [Link]();

HOD hod = new HOD(hName, hID, hSalary, hSubject, hExp, dept);

[Link]();

break;

case 3:

[Link]("Enter Name: ");

String nName = [Link]();

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

int nID = [Link]();

[Link]("Enter Base Salary: ");

double nSalary = [Link]();

[Link]();

[Link]("Enter Role: ");

String role = [Link]();

NonTeachingStaff ns = new NonTeachingStaff(nName, nID, nSalary, role);


[Link]();

break;

default:

[Link]("Invalid choice!");

[Link]();

2. [Link]

class Task extends Thread {

private String taskName;

private int iterations;

public Task(String taskName, int iterations) {

[Link] = taskName;

[Link] = iterations;

@Override

public void run() {

for (int i = 1; i <= iterations; i++) {

[Link](taskName + " - " + i + " by " +


[Link]().getName());

try {

[Link](100); // Simulate task execution

} catch (InterruptedException e) {
[Link](taskName + " interrupted.");

public class TaskScheduling {

public static void main(String[] args) {

// Create threads for different tasks

Task reportThread = new Task("Report generation", 5);

Task transactionThread = new Task("Transaction processing", 5);

Task loggingThread = new Task("Logging activity", 5);

// Set priorities

[Link](Thread.MIN_PRIORITY); // Low priority

[Link](Thread.MAX_PRIORITY); // High priority

[Link](Thread.NORM_PRIORITY); // Medium priority

// Start all threads

[Link]();

[Link]();

[Link]();

Task6:

1. [Link]

import [Link].*;

import [Link];
public class RecipeManagementSystem {

private static final String FILE_NAME = "[Link]";

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

int choice;

do {

[Link]("\n---- Recipe Management System ----");

[Link]("1. Add a new recipe");

[Link]("2. View all recipes");

[Link]("3. Exit");

[Link]("Enter your choice: ");

choice = [Link]();

[Link](); // consume newline

switch (choice) {

case 1:

addRecipe(sc);

break;

case 2:

viewRecipes();

break;

case 3:

[Link]("Exiting Recipe Management System. Goodbye!");

break;

default:
[Link]("Invalid choice! Please enter 1-3.");

} while (choice != 3);

[Link]();

// Method to add a new recipe

private static void addRecipe(Scanner sc) {

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

String name = [Link]();

[Link]("Enter recipe instructions: ");

String instructions = [Link]();

try (FileWriter fw = new FileWriter(FILE_NAME, true);

BufferedWriter bw = new BufferedWriter(fw)) {

[Link]("Recipe Name: " + name + "\n");

[Link]("Instructions: " + instructions + "\n");

[Link]("--------------------------------------------------\n");

[Link]("Recipe saved successfully!");

} catch (IOException e) {

[Link]("Error saving recipe: " + [Link]());

// Method to view all recipes


private static void viewRecipes() {

try (FileReader fr = new FileReader(FILE_NAME);

BufferedReader br = new BufferedReader(fr)) {

String line;

[Link]("\nRecipes in the Recipe Book:\n");

while ((line = [Link]()) != null) {

[Link](line);

} catch (FileNotFoundException e) {

[Link]("No recipes found. Please add some first.");

} catch (IOException e) {

[Link]("Error reading recipes: " + [Link]());

2. [Link]

import [Link];

// Common interface for all payment methods

interface Payment {

void pay(double amount);

// Credit Card payment class

class CreditCardPayment implements Payment {

@Override
public void pay(double amount) {

double charge = amount * 0.02; // 2% charge

[Link]("Processing Rs." + amount + " via Credit Card. 2% charge applied.


Total: Rs." + (amount + charge));

// PayPal payment class

class PayPalPayment implements Payment {

@Override

public void pay(double amount) {

double fee = 5; // Flat Rs.5 fee

[Link]("Processing Rs." + amount + " via PayPal. Rs.5 flat fee applied.
Total: Rs." + (amount + fee));

// UPI payment class

class UPIPayment implements Payment {

@Override

public void pay(double amount) {

[Link]("Processing Rs." + amount + " via UPI. No additional charges.");

public class OnlinePaymentSystem {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);


[Link]("Enter the amount to pay: Rs.");

double amount = [Link]();

[Link]();

[Link]("\nSelect Payment Method:");

[Link]("1. Credit Card");

[Link]("2. PayPal");

[Link]("3. UPI");

[Link]("Your choice: ");

int choice = [Link]();

Payment paymentMethod;

// Dynamic method dispatch

switch (choice) {

case 1:

paymentMethod = new CreditCardPayment();

break;

case 2:

paymentMethod = new PayPalPayment();

break;

case 3:

paymentMethod = new UPIPayment();

break;

default:

[Link]("Invalid choice!");

[Link]();

return;
}

// The actual pay() method called is determined at runtime

[Link](amount);

[Link]();

Task-7:

1. Development of a Console-Based Text Editing Tool Using Java StringBuffer


[Link]

import [Link];

public class TextEditor {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

// Step 1: Initialize StringBuffer with user input

[Link]("Enter initial text: ");

StringBuffer textBuffer = new StringBuffer([Link]());

[Link]("Current Text: " + textBuffer);

// Step 2: Menu-driven operations

while (true) {

[Link]("\nChoose an operation:");

[Link]("1. Append text");

[Link]("2. Insert text");

[Link]("3. Replace text");


[Link]("4. Delete text");

[Link]("5. Reverse text");

[Link]("6. Set specific character");

[Link]("7. Set length");

[Link]("8. Show char at index");

[Link]("9. Show capacity & length");

[Link]("10. Exit");

[Link]("Enter your choice (1-10): ");

int choice = [Link]();

[Link](); // Clear newline

switch (choice) {

case 1: // Append text

[Link]("Enter text to append: ");

String appendText = [Link]();

[Link](appendText);

break;

case 2: // Insert text

[Link]("Enter position to insert at: ");

int insertPos = [Link]();

[Link]();

[Link]("Enter text to insert: ");

String insertText = [Link]();

if (insertPos >= 0 && insertPos <= [Link]()) {

[Link](insertPos, insertText);

} else {
[Link]("Invalid position!");

break;

case 3: // Replace text

[Link]("Enter start index: ");

int start = [Link]();

[Link]("Enter end index: ");

int end = [Link]();

[Link]();

[Link]("Enter replacement text: ");

String replaceText = [Link]();

if (start >= 0 && end <= [Link]() && start < end) {

[Link](start, end, replaceText);

} else {

[Link]("Invalid range!");

break;

case 4: // Delete text

[Link]("Enter start index: ");

int delStart = [Link]();

[Link]("Enter end index: ");

int delEnd = [Link]();

[Link]();

if (delStart >= 0 && delEnd <= [Link]() && delStart < delEnd) {

[Link](delStart, delEnd);

} else {
[Link]("Invalid range!");

break;

case 5: // Reverse text

[Link]();

break;

case 6: // Set specific character

[Link]("Enter index to modify: ");

int index = [Link]();

[Link]();

[Link]("Enter new character: ");

char ch = [Link]().charAt(0);

if (index >= 0 && index < [Link]()) {

[Link](index, ch);

} else {

[Link]("Invalid index!");

break;

case 7: // Set length

[Link]("Enter new length: ");

int newLength = [Link]();

[Link]();

[Link](newLength);

break;
case 8: // Show character at index

[Link]("Enter index to view character: ");

int viewIndex = [Link]();

[Link]();

if (viewIndex >= 0 && viewIndex < [Link]()) {

[Link]("Character at index " + viewIndex + ": " +


[Link](viewIndex));

} else {

[Link]("Invalid index!");

break;

case 9: // Show capacity and length

[Link]("Current Capacity: " + [Link]());

[Link]("Current Length: " + [Link]());

break;

case 10: // Exit

[Link]("Exiting editor. Goodbye!");

[Link]();

return;

default:

[Link]("Invalid choice! Please enter 1-10.");

// Display current text after each operation

[Link]("\nCurrent Text: " + textBuffer);


}

2. [Link]

import [Link].*;

import [Link];

public class MessageStorageSystem {

private static final String FILE_NAME = "[Link]";

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

int choice;

do {

[Link]("\n----------- Message Storage & Retrieval System -----------");

[Link]("1. Write a new message");

[Link]("2. Read all messages");

[Link]("3. Exit");

[Link]("Enter your choice: ");

choice = [Link]();

[Link](); // consume newline

switch (choice) {

case 1:

writeMessage(sc);

break;

case 2:
readMessages();

break;

case 3:

[Link]("Exiting system. Goodbye!");

break;

default:

[Link]("Invalid choice! Enter 1-3.");

} while (choice != 3);

[Link]();

// Method to write a new message to the file

private static void writeMessage(Scanner sc) {

[Link]("Enter your message: ");

String message = [Link]();

try (FileWriter fw = new FileWriter(FILE_NAME, true);

BufferedWriter bw = new BufferedWriter(fw)) {

[Link](message);

[Link](); // Separate messages by newline

[Link]("Message saved successfully!");

} catch (IOException e) {

[Link]("Error saving message: " + [Link]());

}
// Method to read all messages from the file

private static void readMessages() {

try (FileReader fr = new FileReader(FILE_NAME);

BufferedReader br = new BufferedReader(fr)) {

String line;

[Link]("Messages in file:");

while ((line = [Link]()) != null) {

[Link](line);

} catch (FileNotFoundException e) {

[Link]("No messages found. Please write some first.");

} catch (IOException e) {

[Link]("Error reading messages: " + [Link]());

Task-8:

1. Online Exam Evaluation System

1️⃣ Package: [Link]

[Link]

package [Link];

public interface Exam {

void startExam();

void evaluateScore(int score) throws Exception;

}
2️⃣ Package: [Link]

[Link]

package [Link];

public class FailException extends Exception {

public FailException(String message) {

super(message);

3️⃣ Package: [Link]

[Link]

package [Link];

import [Link];

import [Link];

public class ExamPortal implements Exam {

private static final int PASSING_SCORE = 40;

@Override

public void startExam() {

[Link]("Exam Started... Answer all questions.");

@Override

public void evaluateScore(int score) throws FailException {

if (score < PASSING_SCORE) {

throw new FailException("Fail — Score below passing threshold.");

} else {

[Link]("Result: Pass — Congratulations!");


}

4️⃣ Package: [Link]

[Link]

package [Link];

import [Link];

import [Link];

import [Link];

import [Link];

public class MainApp {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

Exam exam = new ExamPortal();

[Link]();

try {

[Link]("Enter your score (0 - 100): ");

int score = [Link]();

if (score < 0 || score > 100) {

[Link]("Error: Score must be between 0 and 100.");

} else {

[Link](score);

} catch (FailException fe) {

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

} catch (Exception e) {

[Link]("Error: Invalid input. Please enter numeric scores.");


} finally {

[Link]("Thank you for attending the exam.");

[Link]();

5. Fare Calculation System for a Travel Agency [Link]

import [Link];

class TravelAgency {

private String customerName;

private double totalFare;

public TravelAgency(String customerName) {

[Link] = customerName;

// Method 1: Basic Taxi Ride (distance only)

public void calculateFare(double distance) {

double ratePerKm = 15; // fixed rate per km

totalFare = distance * ratePerKm;

[Link]("Taxi Fare calculated.");

// Method 2: Bus Ride (distance and number of passengers)

public void calculateFare(double distance, int passengers) {

double ratePerKmPerPassenger = 5; // fare per km per passenger


totalFare = distance * passengers * ratePerKmPerPassenger;

[Link]("Bus Fare calculated.");

// Method 3: Luxury Ride (distance, vehicle type, toll charges)

public void calculateFare(double distance, String vehicleType, double tollCharge) {

double ratePerKm;

if ([Link]("SUV")) {

ratePerKm = 30;

} else if ([Link]("Sedan")) {

ratePerKm = 25;

} else {

ratePerKm = 20; // default luxury rate

totalFare = distance * ratePerKm + tollCharge;

[Link]("Luxury Ride Fare calculated.");

// Display travel summary

public void displaySummary() {

[Link]("\n--- Travel Fare Summary ---");

[Link]("Customer Name : " + customerName);

[Link]("Total Fare : %.2f\n", totalFare);

public class TravelAgencyFareSystem {

public static void main(String[] args) {


Scanner sc = new Scanner([Link]);

[Link]("Enter Customer Name: ");

String name = [Link]();

TravelAgency trip = new TravelAgency(name);

[Link]("Choose Trip Type:");

[Link]("1. Basic Taxi Ride");

[Link]("2. Bus Ride with Passengers");

[Link]("3. Luxury Ride with Toll");

[Link]("Enter your choice: ");

int choice = [Link]();

switch (choice) {

case 1:

[Link]("Enter distance (km): ");

double taxiDistance = [Link]();

[Link](taxiDistance);

break;

case 2:

[Link]("Enter distance (km): ");

double busDistance = [Link]();

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

int passengers = [Link]();

[Link](busDistance, passengers);

break;

case 3:

[Link]("Enter distance (km): ");


double luxDistance = [Link]();

[Link](); // consume newline

[Link]("Enter vehicle type (SUV/Sedan): ");

String vehicleType = [Link]();

[Link]("Enter toll charges: ");

double toll = [Link]();

[Link](luxDistance, vehicleType, toll);

break;

default:

[Link]("Invalid choice!");

[Link]();

return;

[Link]();

[Link]();

Task-9

1. [Link]

1️⃣ Class: [Link]

public class Invoice {

private String partNumber;

private String partDescription;

private int quantity;

private double pricePerItem;

public Invoice(String partNumber, String partDescription, int quantity, double


pricePerItem) {
[Link] = partNumber;

[Link] = partDescription;

setQuantity(quantity);

setPricePerItem(pricePerItem);

public void setPartNumber(String partNumber) {

[Link] = partNumber;

public String getPartNumber() {

return partNumber;

public void setPartDescription(String partDescription) {

[Link] = partDescription;

public String getPartDescription() {

return partDescription;

public void setQuantity(int quantity) {

if (quantity > 0)

[Link] = quantity;

else

[Link] = 0;

public int getQuantity() {

return quantity;
}

public void setPricePerItem(double pricePerItem) {

if (pricePerItem > 0)

[Link] = pricePerItem;

else

[Link] = 0.0;

public double getPricePerItem() {

return pricePerItem;

// Method to calculate invoice amount

public double getInvoiceAmount() {

return quantity * pricePerItem;

2️⃣ Test Application: [Link]

import [Link];

public class InvoiceTest {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

[Link]("Enter Part Number: ");

String partNumber = [Link]();


[Link]("Enter Part Description: ");

String partDescription = [Link]();

[Link]("Enter Quantity: ");

int quantity = [Link]();

[Link]("Enter Price per Item: ");

double pricePerItem = [Link]();

// Create Invoice object

Invoice invoice = new Invoice(partNumber, partDescription, quantity, pricePerItem);

// Display Invoice Details

[Link]("\n--- Invoice Details ---");

[Link]("Part Number: " + [Link]());

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

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

[Link]("Price per Item: " + [Link]());

[Link]("Total Invoice Amount: " + [Link]());

[Link]();

2. Main Program: [Link]

import [Link];

import [Link];
public class BankWithdrawalSystem {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

double balance = 5000.0;

[Link]("Welcome to ABC Bank");

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

try {

[Link]("Enter amount to withdraw: Rs.");

double withdrawAmount = [Link]();

// Check for negative or zero withdrawal

if (withdrawAmount <= 0) {

throw new IllegalArgumentException("Withdrawal amount must be positive.");

// Check for insufficient funds

if (withdrawAmount > balance) {

throw new InsufficientFundsException("Insufficient balance! You have only Rs." +


balance);

// Successful withdrawal

balance -= withdrawAmount;

[Link]("Withdrawal successful! Remaining balance: Rs." + balance);

} catch (InputMismatchException e) {
[Link]("Error: Invalid input type. Please enter numeric values only.");

} catch (IllegalArgumentException e) {

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

} catch (InsufficientFundsException e) {

[Link]("Transaction Failed: " + [Link]());

} finally {

[Link]("Thank you for banking with us.");

[Link]();

Task-10:

1. Smart Home Device Control System

1️⃣ Package: [Link]

[Link]

package [Link];2

public interface SmartDevice {

void turnOn();

void turnOff();

String getStatus();

[Link]

package [Link];

public class SmartLight implements SmartDevice {

private boolean isOn = false;


@Override

public void turnOn() {

isOn = true;

[Link]("Smart Light is turned ON.");

@Override

public void turnOff() {

isOn = false;

[Link]("Smart Light is turned OFF.");

@Override

public String getStatus() {

return isOn ? "Smart Light is ON." : "Smart Light is OFF.";

[Link]

package [Link];

public class SmartFan implements SmartDevice {

private boolean isOn = false;

@Override

public void turnOn() {

isOn = true;

[Link]("Smart Fan is turned ON.");


}

@Override

public void turnOff() {

isOn = false;

[Link]("Smart Fan is turned OFF.");

@Override

public String getStatus() {

return isOn ? "Smart Fan is ON." : "Smart Fan is OFF.";

[Link]

package [Link];

public class SmartThermostat implements SmartDevice {

private boolean isOn = false;

@Override

public void turnOn() {

isOn = true;

[Link]("Smart Thermostat is turned ON.");

@Override

public void turnOff() {


isOn = false;

[Link]("Smart Thermostat is turned OFF.");

@Override

public String getStatus() {

return isOn ? "Smart Thermostat is ON." : "Smart Thermostat is OFF.";

2️⃣ Package: [Link]

[Link]

package [Link];

import [Link].*;

import [Link];

public class SmartHomeControlPanel {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

SmartDevice device = null;

boolean exit = false;

[Link]("Welcome to Smart Home Control Panel");

while (!exit) {

[Link]("\nChoose device to control:");

[Link]("1. Smart Light");


[Link]("2. Smart Fan");

[Link]("3. Smart Thermostat");

[Link]("4. Exit");

[Link]("Enter your choice: ");

int deviceChoice = [Link]();

switch (deviceChoice) {

case 1:

device = new SmartLight();

break;

case 2:

device = new SmartFan();

break;

case 3:

device = new SmartThermostat();

break;

case 4:

exit = true;

continue;

default:

[Link]("Invalid choice! Please enter 1-4.");

continue;

boolean deviceExit = false;

while (!deviceExit) {

[Link]("\n1. Turn ON");

[Link]("2. Turn OFF");


[Link]("3. Get Status");

[Link]("4. Exit to main menu");

[Link]("Choose an action: ");

int action = [Link]();

switch (action) {

case 1:

[Link]();

break;

case 2:

[Link]();

break;

case 3:

[Link]([Link]());

break;

case 4:

deviceExit = true;

break;

default:

[Link]("Invalid action! Please enter 1-4.");

[Link]("Exiting control panel...");

[Link]();

}
2. [Link]

import [Link];

class Employee {

private String name;

private int employeeID;

private String department;

private double basicSalary;

// Constructor

public Employee(String name, int employeeID, String department, double basicSalary) {

[Link] = name;

[Link] = employeeID;

[Link] = department;

[Link] = basicSalary;

// Getters

public String getName() {

return name;

public int getEmployeeID() {

return employeeID;

public String getDepartment() {

return department;

}
public double getBasicSalary() {

return basicSalary;

// Calculate gross salary

public double calculateGrossSalary() {

double hra = 0.20 * basicSalary; // 20% HRA

double da = 0.10 * basicSalary; // 10% DA

return basicSalary + hra + da;

public class EmployeeManagementSystem {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

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

int n = [Link]();

[Link](); // consume newline

Employee[] employees = new Employee[n];

for (int i = 0; i < n; i++) {

[Link]("\nEnter details for Employee " + (i + 1));

[Link]("Enter Name: ");

String name = [Link]();

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


int id = [Link]();

[Link](); // consume newline

[Link]("Enter Department: ");

String dept = [Link]();

[Link]("Enter Basic Salary: ");

double basicSalary = [Link]();

[Link](); // consume newline

employees[i] = new Employee(name, id, dept, basicSalary);

[Link]("\n--- Employee Details ---");

for (Employee emp : employees) {

[Link]("Employee ID: " + [Link]());

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

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

[Link]("Basic Salary: " + [Link]());

[Link]("Gross Salary: " + [Link]());

[Link]("------------------------------");

[Link]();

You might also like