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

Java Method Overloading Examples

The document contains a report on various programming assignments completed by a student named Somesh at Galgotias University, focusing on method overloading in Java. It includes problem statements, descriptions, input/output formats, source code, and compilation details for multiple tasks such as a calculator, bank account, employee salary calculator, and volume finder. Each task demonstrates concepts of polymorphism and method overloading with sample inputs and expected outputs.
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)
4 views106 pages

Java Method Overloading Examples

The document contains a report on various programming assignments completed by a student named Somesh at Galgotias University, focusing on method overloading in Java. It includes problem statements, descriptions, input/output formats, source code, and compilation details for multiple tasks such as a calculator, bank account, employee salary calculator, and volume finder. Each task demonstrates concepts of polymorphism and method overloading with sample inputs and expected outputs.
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

Codekata Report:

Name: Somesh

Email: somesh.24scse1180003@[Link]

Specialization: School of Computer Science & Engineering

Completion Year: 2028-3rd Sem

Section: Section-37

)
.in
ac
1. Problem Statement:Write a program to implement method

ty.
rsi
overloading in which a class provides multiple calculate methods

ive
that handle addition of two integers, two floating-point numbers,
n
and concatenation of two strings. su
tia
lgo

Description:The program should demonstrate polymorphism by defining three


ga

overloaded methods named calculate. The main method should take user input,
3@

determine the type of data entered, and call the appropriate method dynamically.
00

Input Format:First line: Data type (int, float, or string)Next two lines: Values of that
80

type
1
e1

Output Format:
cs
4s

Result after applying the overloaded calculate method


h.2
es

Sample Input:int1020
m
so

Sample Output:30
h(
es
m

Completion Status: Completed


So

Concepts Included:
GU 28 3rd Sem Java Prog. Pre-Midterm

Language Used: JAVA 8

Source Code:
import [Link];

class Calculator {
int calculate(int a, int b) {
return a + b;
}

double calculate(double a, double b) {


return a + b;
}

String calculate(String a, String b) {


return a + b;
}
}

public class Main {


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

)
.in
ac
if (![Link]()) {

ty.
[Link]();

rsi
return;

ive
}

n
su
tia
String type = [Link]().trim().toLowerCase(); // reads the data type token (handles
lgo

"int", "string", etc.)


// Move to the next line so that subsequent nextLine() calls start fresh when needed
ga

[Link]();
3@
00

switch (type) {
80

case "int":
1
e1

case "integer": {
cs

// read two integer tokens (works if they are on same or different lines)
4s

Scanner lineScanner = new Scanner([Link]().trim());


h.2

Integer a = null, b = null;


es

if ([Link]()) {
m

try { a = [Link]([Link]()); } catch (Exception e) { a = null; }


so

}
h(

if ([Link]()) {
es

try { b = [Link]([Link]()); } catch (Exception e) { b = null; }


m

}
So

// if not both read from that line, read remaining tokens from sc
if (a == null || b == null) {
if (a == null && [Link]()) a = [Link]();
else if (a == null && [Link]()) {
try { a = [Link]([Link]()); } catch (Exception e) {}
}
if (b == null && [Link]()) b = [Link]();
else if (b == null && [Link]()) {
try { b = [Link]([Link]()); } catch (Exception e) {}
}
}
[Link]();
if (a != null && b != null) {
[Link]([Link](a, b));
}
break;
}

case "float":
case "double": {
// read two numeric tokens (double covers float and double inputs)
Scanner lineScanner = new Scanner([Link]().trim());
Double a = null, b = null;
if ([Link]()) {
try { a = [Link]([Link]()); } catch (Exception e) { a = null; }
}
if ([Link]()) {
try { b = [Link]([Link]()); } catch (Exception e) { b = null; }
}
if (a == null || b == null) {
if (a == null && [Link]()) {

)
.in
try { a = [Link]([Link]()); } catch (Exception e) {}

ac
}

ty.
if (b == null && [Link]()) {

rsi
try { b = [Link]([Link]()); } catch (Exception e) {}

ive
}

n
}
su
tia
[Link]();
lgo

if (a != null && b != null) {


double res = [Link](a, b);
ga

// print without .0 if it's a whole number


3@

if (res == [Link](res)) {
00

[Link]((long)[Link](res));
80

} else {
1
e1

[Link](res);
cs

}
4s

}
h.2

break;
es

}
m
so

case "string":
h(

case "str": {
es

// read two lines as full strings (allows spaces)


m

String s1 = [Link]() ? [Link]() : "";


So

// If the first line is empty (could be because type was on its own line), keep reading
if ([Link]() && [Link]()) s1 = [Link]();
String s2 = [Link]() ? [Link]() : "";
if ([Link]() && [Link]()) s2 = [Link]();
// fallback to tokens if lines are empty
if ((s1 == null || [Link]() == 0) && [Link]()) s1 = [Link]();
if ((s2 == null || [Link]() == 0) && [Link]()) s2 = [Link]();
[Link]([Link](s1 == null ? "" : s1, s2 == null ? "" : s2));
break;
}

default:

String a = [Link]() ? [Link]() : "";


String b = [Link]() ? [Link]() : "";
if (a == null) a = "";
if (b == null) b = "";
[Link](a + b);
}

[Link]();
}
}

Compilation Details:

TestCase1:
Input:

)
< hidden >

.in
ac
Expected Output:

ty.
rsi
< hidden >

n ive
Output: su
tia
lgo

19.8
ga

Compilation Status: Passed


3@
00

Execution Time:
801

0.089s
e1
cs
4s

TestCase2:
h.2

Input:
es
m
so

< hidden >


h(

Expected Output:
es
m
So

< hidden >

Output:
HelloWorld

Compilation Status: Passed


Execution Time:
0.098s

TestCase3:
Input:
< hidden >

Expected Output:
< hidden >

Output:
-1

Compilation Status: Passed


Execution Time:
0.093s

TestCase4:

)
.in
ac
Input:

ty.
rsi
< hidden >

ive
Expected Output:
n
su
tia
< hidden >
lgo

Output:
ga
3@

OpenAI
00
80

Compilation Status: Passed


1
e1

Execution Time:
cs
4s

0.094s
h.2
es
m
so

2. Bank Account with Overloaded Methods


h(
es

Problem Statement:Create a BankAccount class with method overloading to deposit


m

money using either int or double. Compute the total balance after deposits.
So

Description:Demonstrates compile-time polymorphism, arithmetic calculation, and


method overloading.

Input Format:

initialBalancenumberOfDepositsdeposit1 deposit2 ...

Output Format:

Total Balance: <value>

Sample Input:
500031000 2000 500
Sample Output:
Total Balance: 8500

Completion Status: Completed

Concepts Included:
GU 28 3rd Sem Java Prog. Pre-Midterm

Language Used: JAVA 8

Source Code:

)
.in
import [Link].*;

ac
class BankAccount {

ty.
double balance;

rsi
BankAccount(double initialBalance) {

ive
[Link] = initialBalance;

n
} su
tia
lgo

void deposit(int amount) {


ga

balance += amount;
3@

}
00
80

void deposit(double amount) {


1

balance += amount;
e1

}
cs

double getBalance() {
4s

return balance;
h.2

}
es

}
m

public class Main {


so

public static void main(String[] args) {


h(

Scanner sc = new Scanner([Link]);


es
m
So

double initialBalance = [Link]();


BankAccount account = new BankAccount(initialBalance);

int n = [Link]();

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


if ([Link]()) {
[Link]([Link]());
} else if ([Link]()) {
[Link]([Link]());
}
}

[Link]("Total Balance: " + (int) [Link]());


[Link]();
}
}

Compilation Details:

TestCase1:
Input:
< hidden >

Expected Output:
< hidden >

Output:

)
.in
ac
Total Balance: 2000

ty.
rsi
Compilation Status: Passed

ive
Execution Time:
n
su
tia
0.12s
lgo
ga

TestCase2:
3@
00

Input:
801

< hidden >


e1
cs

Expected Output:
4s
h.2

< hidden >


es
m

Output:
so
h(

Total Balance: 2151


es
m

Compilation Status: Passed


So

Execution Time:
0.126s

TestCase3:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Total Balance: 1000

Compilation Status: Passed


Execution Time:
0.128s

3. Employee Salary Calculator (Method Overloading)


Problem Statement:Write a program to demonstrate method overloading by creating
a class Employee with overloaded methods calculateSalary().

One method should accept base salary only.

Another should accept base salary and bonus.

)
.in
Another should accept base salary, bonus, and deductions.

ac
ty.
Description:Use method overloading to calculate salary with different parameters.

rsi
ive
Input Format:

n
First line: base salary su
tia
lgo

Second line: bonus (optional)


ga
3@

Third line: deductions (optional)


00

Output Format:Final calculated salary


801
e1

Sample Input:
cs
4s

3000050002000
h.2
es

Sample Output:
m
so
h(

33000
es
m
So

Completion Status: Completed

Concepts Included:
GU 28 3rd Sem Java Prog. Pre-Midterm

Language Used: JAVA 8

Source Code:
import [Link].*;
class Employee {

public double calculateSalary(double base) {


return base;
}
public double calculateSalary(double base, double bonus) {
return base + bonus;
}
public double calculateSalary(double base, double bonus, double deductions) {
return base + bonus - deductions;
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
Employee emp = new Employee();

List<Double> inputs = new ArrayList<>();


while ([Link]()) {

)
.in
[Link]([Link]());

ac
}

ty.
[Link]();

rsi
double result = 0.0;

n ive
if ([Link]() == 1) {
su
tia
result = [Link]([Link](0));
lgo

} else if ([Link]() == 2) {
result = [Link]([Link](0), [Link](1));
ga

} else if ([Link]() >= 3) {


3@

result = [Link]([Link](0), [Link](1), [Link](2));


00

}
801
e1

if (result == [Link](result)) {
cs

[Link]((int) result);
4s

} else {
h.2

[Link](result);
es

}
m

}
so

}
h(
es
m

Compilation Details:
So

TestCase1:
Input:
< hidden >

Expected Output:
< hidden >

Output:
55000

Compilation Status: Passed


Execution Time:
0.104s

TestCase2:
Input:
< hidden >

Expected Output:
< hidden >

Output:
30000

)
.in
ac
Compilation Status: Passed

ty.
rsi
Execution Time:

n ive
0.101s
su
tia
lgo

TestCase3:
ga

Input:
3@
00

< hidden >


801

Expected Output:
e1
cs

< hidden >


4s
h.2

Output:
es
m

8000
so
h(

Compilation Status: Passed


es
m

Execution Time:
So

0.105s

TestCase4:
Input:
< hidden >

Expected Output:
< hidden >

Output:
4500
Compilation Status: Passed
Execution Time:
0.122s

4. Volume Finder
Problem Statement:Write a program using method overloading

Description:Find the volume of:

1. Cube (side)

2. Cuboid (length, breadth, height)

)
3. Cylinder (radius, height)

.in
ac
Input Format:User chooses shape and provides dimensions.

ty.
rsi
Output Format:Volume of the chosen shape.

n ive
Sample Input:cylinder3 7
su
tia
lgo

Sample Output:
ga
3@

197.92
00
80

Completion Status: Completed


1
e1
cs
4s

Concepts Included:
h.2

GU 28 3rd Sem Java Prog. Pre-Midterm


es
m
so

Language Used: JAVA 8


h(
es
m

Source Code:
So

import [Link].*;
class VolumeFinder {

public double volume(double side) {


return side * side * side;
}

public double volume(double length, double breadth, double height) {


return length * breadth * height;
}

public double volume(double radius, double height, boolean isCylinder) {


return [Link] * radius * radius * height;
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
VolumeFinder vf = new VolumeFinder();
String shape = [Link]().trim().toLowerCase();
double result = 0.0;

switch (shape) {
case "cube": {
double side = [Link]();
result = [Link](side);
break;
}
case "cuboid": {
double l = [Link]();

)
.in
double b = [Link]();

ac
double h = [Link]();

ty.
result = [Link](l, b, h);

rsi
break;

ive
}

n
case "cylinder": {
su
tia
double r = [Link]();
lgo

double h = [Link]();
result = [Link](r, h, true);
ga

break;
3@

}
00

default:
80

[Link]("Invalid shape");
1
e1

[Link]();
cs

return;
4s

}
h.2
es

[Link]("%.2f%n", result);
m

[Link]();
so

}
h(

}
es
m
So

Compilation Details:

TestCase1:
Input:
< hidden >

Expected Output:
< hidden >

Output:
125.00
Compilation Status: Passed
Execution Time:
0.108s

TestCase2:
Input:
< hidden >

Expected Output:
< hidden >

Output:

)
.in
ac
24.00

ty.
rsi
Compilation Status: Passed

n ive
Execution Time:
su
tia
0.107s
lgo
ga

TestCase3:
3@
00

Input:
801

< hidden >


e1
cs

Expected Output:
4s
h.2

< hidden >


es
m

Output:
so
h(

785.40
es
m

Compilation Status: Passed


So

Execution Time:
0.11s

TestCase4:
Input:
< hidden >

Expected Output:
< hidden >

Output:
15.63

Compilation Status: Passed


Execution Time:
0.104s

5. Banking System with Static Interest RateProblem


StatementCreate a banking system where the interest rate is static
across all accounts. Demonstrate deposits, withdrawals, and
interest calculation.
Description1. Define a class BankAccount with variables: balance (for storing account
balance).2. Use a static variable interestRate applicable to all accounts.3. Implement

)
.in
methods: deposit(amount) Adds money to balance. withdraw(amount) Deducts

ac
money if sufficient balance exists. calculateInterest() Returns interest based on

ty.
current balance and static interest rate.4. After deposit and withdrawal, calculate

rsi
interest and display the final balance and interest.

n ive
Input FormatInitial deposit amountWithdrawal amount
su
tia
Output FormatBalanceInterest
lgo
ga

Sample Input50002000
3@

Sample Output3000.0150
00
801
e1

Completion Status: Completed


cs
4s
h.2

Concepts Included:
es
m

GU 28 3rd Sem Java Prog. Pre-Midterm


so
h(

Language Used: JAVA 8


es
m
So

Source Code:
import [Link].*;
class BankAccount {
double balance;
static double interestRate = 5.0;

BankAccount(double initialDeposit) {
balance = initialDeposit;
}
public void deposit(double amount) {
balance += amount;
}
public void withdraw(double amount) {
if (amount <= balance) balance -= amount;
}

public double calculateInterest() {


return (balance * interestRate) / 100.0;
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
double initialDeposit = [Link]();
double withdrawalAmount = [Link]();
BankAccount account = new BankAccount(initialDeposit);
[Link](withdrawalAmount);
double interest = [Link]();
[Link]([Link]);
[Link]((int) interest);

)
.in
}

ac
}

ty.
rsi
Compilation Details:

n ive
su
tia
TestCase1:
lgo

Input:
ga
3@

< hidden >


00
80

Expected Output:
1
e1

< hidden >


cs
4s

Output:
h.2
es

6000.0
m

300
so
h(

Compilation Status: Passed


es
m

Execution Time:
So

0.105s

TestCase2:
Input:
< hidden >

Expected Output:
< hidden >

Output:
5000.0
250

Compilation Status: Passed


Execution Time:
0.099s

TestCase3:
Input:
< hidden >

Expected Output:
< hidden >

)
.in
ac
Output:

ty.
rsi
10000.0

ive
500

n
Compilation Status: Passed su
tia
lgo

Execution Time:
ga
3@

0.114s
00
80

TestCase4:
1
e1

Input:
cs
4s

< hidden >


h.2
es

Expected Output:
m
so

< hidden >


h(
es

Output:
m
So

7000.0
350

Compilation Status: Passed


Execution Time:
0.1s

6. Passing this as Argument with Garage System


Problem Statement:Write a program where a Car object passes itself using the this
keyword to a Garage class method. The garage should assign a slot to each car
parked and display all parked cars with their slot numbers.
Description:

Create two classes: Car and Garage.

The Car object uses the this keyword to call the parkCar(Car c) method of the Garage.

Each parked car should be assigned an incrementing slot number.

The garage should also be able to display the list of all parked cars.

Input Format:

An integer n (number of cars).

For each car:

Car brand

Car model

)
.in
ac
Output Format:

ty.
rsi
Confirmation message for each parked car with its slot number.

ive
A garage status list showing all parked cars and their slot assignments.

n
su
tia
lgo

Sample Input:
ga

2TeslaModel SBMWX5
3@
00

Sample Output:
801
e1

Car Tesla Model S has been parked in slot #1Car BMW X5 has been parked in slot #2
cs
4s

--- Garage Status ---Slot 1: Tesla Model SSlot 2: BMW X5


h.2
es
m

Completion Status: Completed


so
h(
es

Concepts Included:
m
So

GU 28 3rd Sem Java Prog. Pre-Midterm

Language Used: JAVA 8

Source Code:
import [Link].*;
class Car {
String brand;
String model;

Car(String brand, String model) {


[Link] = brand;
[Link] = model;
}

public void parkCar(Garage g) {


[Link](this);
}
}

class Garage {
private static int slotCounter = 0;
private LinkedHashMap<Integer, Car> parkedCars = new LinkedHashMap<>();

public void parkCar(Car c) {


slotCounter++;
[Link](slotCounter, c);
[Link]("Car " + [Link] + " " + [Link] + " has been parked in slot #" +
slotCounter);

)
.in
}

ac
ty.
public void displayGarageStatus() {

rsi
[Link]("\n--- Garage Status ---");

ive
for ([Link]<Integer, Car> entry : [Link]()) {

n
[Link]("Slot " + [Link]() + ": " + [Link]().brand + " " +
su
tia
[Link]().model);
lgo

}
}
ga

}
3@
00

public class Main {


80

public static void main(String[] args) {


1
e1

Scanner sc = new Scanner([Link]);


cs

Garage garage = new Garage();


4s

int n = [Link]();
h.2

[Link]();
es

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


m

String brand = [Link]().trim();


so

String model = [Link]().trim();


h(

Car car = new Car(brand, model);


es

[Link](garage);
m

}
So

[Link]();
}
}

Compilation Details:

TestCase1:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Car Ford Mustang has been parked in slot #1

--- Garage Status ---


Slot 1: Ford Mustang

Compilation Status: Passed


Execution Time:
0.138s

TestCase2:

)
.in
Input:

ac
ty.
< hidden >

rsi
ive
Expected Output:

n
< hidden > su
tia
lgo

Output:
ga
3@

Car Hyundai Creta has been parked in slot #1


00

Car Maruti Swift has been parked in slot #2


80

Car Kia Seltos has been parked in slot #3


1
e1

--- Garage Status ---


cs

Slot 1: Hyundai Creta


4s

Slot 2: Maruti Swift


h.2

Slot 3: Kia Seltos


es
m

Compilation Status: Passed


so
h(

Execution Time:
es
m

0.141s
So

TestCase3:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Car Mercedes GLA has been parked in slot #1
Car Jaguar XF has been parked in slot #2
--- Garage Status ---
Slot 1: Mercedes GLA
Slot 2: Jaguar XF

Compilation Status: Passed


Execution Time:
0.141s

TestCase4:
Input:
< hidden >

)
.in
Expected Output:

ac
ty.
< hidden >

rsi
ive
Output:

n
Car Honda Civic has been parked in slot #1 su
tia
Car Toyota Fortuner has been parked in slot #2
lgo

Car Audi A4 has been parked in slot #3


ga

Car BMW X3 has been parked in slot #4


3@
00

--- Garage Status ---


80

Slot 1: Honda Civic


1

Slot 2: Toyota Fortuner


e1
cs

Slot 3: Audi A4
4s

Slot 4: BMW X3
h.2

Compilation Status: Passed


es
m

Execution Time:
so
h(

0.14s
es
m
So

7. ConstructorsProblem Statement:Write a program that


demonstrates the use of parameterized constructors by creating a
class representing a rectangle and calculating its area.
Description:The program should have a Rectangle class with a parameterized
constructor to initialize the length and width. The class should have a method to
calculate the area of the rectangle.

Input Format:

Two integers representing the length and width of the [Link] Format:

The area of the [Link] Input:5 10Sample Output:50


Completion Status: Completed

Concepts Included:
GU 28 3rd Sem Java Prog. Pre-Midterm

Language Used: JAVA 8

Source Code:
import [Link].*;
class Rectangle{
int l , w;
Rectangle(int l , int w){
this.l = l;

)
.in
this.w = w;

ac
}

ty.
int calculateArea(){

rsi
return l*w;

ive
}

n
} su
tia
public class Main{
lgo

public static void main(String[] args){


ga

Scanner sc = new Scanner([Link]);


3@

int length = [Link]();


int width = [Link]();
00
80

Rectangle r = new Rectangle(length , width);


1

[Link]([Link]());
e1

}
cs

}
4s
h.2

Compilation Details:
es
m
so

TestCase1:
h(
es

Input:
m
So

< hidden >

Expected Output:
< hidden >

Output:
30

Compilation Status: Passed


Execution Time:
0.088s
TestCase2:
Input:
< hidden >

Expected Output:
< hidden >

Output:
21

Compilation Status: Passed


Execution Time:

)
.in
0.089s

ac
ty.
rsi
TestCase3:

n ive
Input:
su
tia
< hidden >
lgo
ga

Expected Output:
3@

< hidden >


00
80

Output:
1
e1

36
cs
4s

Compilation Status: Passed


h.2
es

Execution Time:
m
so

0.095s
h(
es
m

TestCase4:
So

Input:
< hidden >

Expected Output:
< hidden >

Output:
16

Compilation Status: Passed


Execution Time:
0.093s

8. Uses constructors to initialize a Person object with a name and


ageProblem StatementCreate a program that uses constructors to
initialize a Person object with a name and age. The program should
then read a number of years from the user and update the person's
age, outputting the updated age.
DescriptionDefine a class Person with fields name and age. Use a constructor to
initialize these fields. The program should read the initial name and age, and then
read a number of years to add to the age. Output the updated age.

Input FormatThe first line contains the name (a string).The second line contains the
initial age (an integer).The third line contains the number of years to add (an

)
.in
integer).Output FormatA single line containing the updated age.

ac
Sample Input:Diana2015Sample Output:35

ty.
rsi
n ive
Completion Status: Completed
su
tia
lgo

Concepts Included:
ga
3@

GU 28 3rd Sem Java Prog. Pre-Midterm


00
80

Language Used: JAVA 8


1
e1
cs

Source Code:
4s
h.2

import [Link].*;
es

class Person{
m

String name;
so

int age;
h(

Person(String name , int age){


es

[Link] = name;
m

[Link] = age;
So

}
void displayDetails(){
// [Link](name);
[Link](age);
}
}
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner([Link]);
String name = [Link]();
int age1 = [Link]();
int age2 = [Link]();
int age = age1 + age2;
Person p = new Person(name , age);
[Link]();
}
}

Compilation Details:

TestCase1:
Input:
< hidden >

Expected Output:
< hidden >

Output:

)
.in
ac
41

ty.
rsi
Compilation Status: Passed

ive
Execution Time:
n
su
tia
0.09s
lgo
ga

TestCase2:
3@
00

Input:
801

< hidden >


e1
cs

Expected Output:
4s
h.2

< hidden >


es
m

Output:
so
h(

50
es
m

Compilation Status: Passed


So

Execution Time:
0.092s

TestCase3:
Input:
< hidden >

Expected Output:
< hidden >

Output:
28

Compilation Status: Passed


Execution Time:
0.087s

TestCase4:
Input:
< hidden >

Expected Output:
< hidden >

)
.in
ac
Output:

ty.
rsi
35

ive
Compilation Status: Passed
n
su
tia
Execution Time:
lgo
ga

0.092s
3@
00
80

9. Inventory Management with Constructor Chaining


1
e1

Problem Statement:Write a program to manage product inventory using multi-level


cs

constructor chaining. Create Product Electronics Laptop. Compute final price after
4s

tax and warranty cost.


h.2
es

Description:Demonstrates constructor chaining, inheritance, and arithmetic


m

computation.
so
h(

Input Format:
es
m

basePrice tax warrantyCost


So

Output Format:

Final Price: <value>

Sample Input:
50000 5000 2000

Sample Output:
Final Price: 57000

Completion Status: Completed


Concepts Included:
GU 28 3rd Sem Java Prog. Pre-Midterm

Language Used: JAVA 8

Source Code:
import [Link];
// Base class
class Product {
int price;
// Constructor for Product
Product(int price) {
[Link] = price;

)
}

.in
ac
}

ty.
// Derived class Electronics (extends Product)

rsi
class Electronics extends Product {

ive
int tax;

n
// Constructor for Electronics
Electronics(int price, int tax) { su
tia
super(price); // Calls Product constructor
lgo

[Link] = tax;
ga

}
3@

// Method to calculate price after tax


00

int priceAfterTax() {
80

return price + tax;


1

}
e1

}
cs
4s

// Derived class Laptop (extends Electronics)


h.2

class Laptop extends Electronics {


int warrantyCost;
es
m

// Constructor for Laptop


so

Laptop(int price, int tax, int warrantyCost) {


h(

super(price, tax); // Calls Electronics constructor


es

[Link] = warrantyCost;
m

}
So

// Method to calculate final price


int finalPrice() {
return price + tax + warrantyCost;
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
// Input base price, tax percentage, and warranty cost
int price = [Link]();
int tax = [Link]();
int warranty = [Link]();
// Create Laptop object using multi-level constructor chaining
Laptop laptop = new Laptop(price, tax, warranty);
// Display final price
[Link]("Final Price: "+[Link]());
}
}

Compilation Details:

TestCase1:
Input:
< hidden >

Expected Output:
< hidden >

)
.in
Output:

ac
ty.
Final Price: 44500

rsi
ive
Compilation Status: Passed

n
Execution Time: su
tia
lgo

0.118s
ga
3@

TestCase2:
00
80

Input:
1
e1

< hidden >


cs
4s

Expected Output:
h.2
es

< hidden >


m
so

Output:
h(
es

Final Price: 75000


m
So

Compilation Status: Passed


Execution Time:
0.118s

TestCase3:
Input:
< hidden >

Expected Output:
< hidden >
Output:
Final Price: 33000

Compilation Status: Passed


Execution Time:
0.107s

TestCase4:
Input:
< hidden >

Expected Output:

)
.in
ac
< hidden >

ty.
rsi
Output:

n ive
Final Price: 51000
su
tia
Compilation Status: Passed
lgo
ga

Execution Time:
3@

0.106s
00
801
e1

10. Static Discount Calculator for Multiple Items


cs
4s

Problem Statement:Create a class Item with static variable totalDiscount to


h.2

accumulate discounts across all items. Compute total discount for multiple items.
es
m

Description:Demonstrates static variables, arithmetic accumulation, and object


so

creation.
h(
es

Input Format:
m
So

itemPrice discountPercent

Output Format:

Total Discount: <value>

Sample Input:
1000 10500 5

Sample Output:
Total Discount: 125
Completion Status: Completed

Concepts Included:
GU 28 3rd Sem Java Prog. Pre-Midterm

Language Used: JAVA 8

Source Code:
import [Link].*;
class Item {
double price;
double discountPercent;
static double totalDiscount = 0.0; // static variable to accumulate total discount

)
.in
// Constructor

ac
Item(double price, double discountPercent) {

ty.
[Link] = price;

rsi
[Link] = discountPercent;

ive
addDiscount();

n
} su
tia
// Method to calculate and add discount for this item
lgo

void addDiscount() {
ga

double discount = (price * discountPercent) / 100.0;


3@

totalDiscount += discount;
00
80

}
1

}
e1

public class Main {


cs

public static void main(String[] args) {


4s

Scanner sc = new Scanner([Link]);


h.2

while ([Link]()) {
es

double price = [Link]();


m

double discountPercent = [Link]();


so

new Item(price, discountPercent); // create an item and update total discount


h(

}
es
m

// Output total discount (no decimals in sample output)


So

[Link]("Total Discount: " + (int) [Link]);


[Link]();
}
}

Compilation Details:

TestCase1:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Total Discount: 500

Compilation Status: Passed


Execution Time:
0.114s

TestCase2:
Input:
< hidden >

)
.in
ac
Expected Output:

ty.
rsi
< hidden >

ive
Output:
n
su
tia
Total Discount: 250
lgo

Compilation Status: Passed


ga
3@

Execution Time:
00
80

0.116s
1
e1
cs

TestCase3:
4s
h.2

Input:
es
m

< hidden >


so
h(

Expected Output:
es
m

< hidden >


So

Output:
Total Discount: 450

Compilation Status: Passed


Execution Time:
0.124s

TestCase4:
Input:
< hidden >
Expected Output:
< hidden >

Output:
Total Discount: 280

Compilation Status: Passed


Execution Time:
0.116s

11. Library Book Borrowing SystemProblem StatementDesign a


program for a Library Book Borrowing System using inheritance.

)
.in
ac
Description:Design a program where LibraryItem is a base class. Book and Magazine

ty.
inherit from it. Use method overriding to calculate the late fee depending on the type

rsi
of item.1. Books charge ₹5/day late2. Magazines charge ₹2/day lateUse constructors

ive
and super keyword to initialize.

n
su
tia
Input Format:First line: type of item (book or magazine)Second line: number of late
lgo

days
ga

Output Format:Late fee in ₹


3@
00

Sample Input:book4
80

Sample Output:20
1
e1
cs
4s

Completion Status: Completed


h.2
es
m

Concepts Included:
so
h(

GU 28 3rd Sem Java Prog. Pre-Midterm


es
m
So

Language Used: JAVA 8

Source Code:
import [Link].*;
class LibraryItem {
String itemType;
// Constructor
LibraryItem(String itemType) {
[Link] = itemType;
}
// Method to calculate late fee (overridden in subclasses)
double calculateLateFee(int daysLate) {
return 0.0;
}
}
// Book class inherits LibraryItem
class Book extends LibraryItem {
// Constructor uses super to call parent constructor
Book(String itemType) {
super(itemType);
}
// Overridden method
double calculateLateFee(int daysLate) {
return daysLate * 5; // ₹5 per day
}
}
// Magazine class inherits LibraryItem
class Magazine extends LibraryItem {
// Constructor uses super
Magazine(String itemType) {

)
.in
super(itemType);

ac
ty.
}

rsi
// Overridden method

ive
double calculateLateFee(int daysLate) {

n
return daysLate * 2; // ₹2 per day
su
tia
}
lgo

}
public class Main {
ga

public static void main(String[] args) {


3@

Scanner sc = new Scanner([Link]);


00

String type = [Link]().trim().toLowerCase();


80

int days = [Link]();


1
e1

LibraryItem item;
cs

if ([Link]("book")) {
4s

item = new Book("Book");


h.2

} else if ([Link]("magazine")) {
es

item = new Magazine("Magazine");


m

} else {
so

[Link]("Invalid item type");


h(

return;
es

}
m

[Link]((int) [Link](days));
So

[Link]();
}
}

Compilation Details:

TestCase1:
Input:
< hidden >

Expected Output:
< hidden >

Output:
30

Compilation Status: Passed


Execution Time:
0.103s

TestCase2:
Input:
< hidden >

)
.in
ac
Expected Output:

ty.
rsi
< hidden >

ive
Output:
n
su
tia
20
lgo

Compilation Status: Passed


ga
3@

Execution Time:
00
80

0.094s
1
e1
cs

TestCase3:
4s
h.2

Input:
es
m

< hidden >


so
h(

Expected Output:
es
m

< hidden >


So

Output:
0

Compilation Status: Passed


Execution Time:
0.102s

TestCase4:
Input:
< hidden >
Expected Output:
< hidden >

Output:
6

Compilation Status: Passed


Execution Time:
0.095s

12. Multi-level Discount with Final Variables

)
.in
Problem Statement:Create a Product class and a subclass SpecialProduct. Use final

ac
variable maxDiscount and calculate discount for multiple products.

ty.
rsi
Description:Demonstrates final variables, inheritance, and arithmetic calculations.

ive
Input Format:

n
su
tia
price discount
lgo

Output Format:
ga
3@

Applied Discount: <value>


00
80

Sample Input:
1
e1
cs

2000 500
4s
h.2

Sample Output:
es
m

Applied Discount: 500


so
h(
es

Completion Status: Completed


m
So

Concepts Included:
GU 28 3rd Sem Java Prog. Pre-Midterm

Language Used: JAVA 8

Source Code:
import [Link].*;
class Product {
final double maxDiscount = 500; // final variable
double price;
double discount;
// Constructor
Product(double price, double discount) {
[Link] = price;
[Link] = discount;
}
// Method to calculate applied discount
double calculateDiscount() {
// Apply maxDiscount limit
if (discount > maxDiscount) {
return maxDiscount;

} else {
return discount;
}
}
}

)
.in
// Subclass for possible future extensions

ac
class SpecialProduct extends Product {

ty.
SpecialProduct(double price, double discount) {

rsi
super(price, discount);

ive
}

n
// Could override calculateDiscount() if needed
su
tia
}
lgo

public class Main {


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

Scanner sc = new Scanner([Link]);


3@

while ([Link]()) {
00

double price = [Link]();


80

double discount = [Link]();


1
e1

SpecialProduct sp = new SpecialProduct(price, discount);


cs

[Link]("Applied Discount: " + (int) [Link]());


4s

}
h.2

}
es

}
m
so

Compilation Details:
h(
es
m

TestCase1:
So

Input:
< hidden >

Expected Output:
< hidden >

Output:
Applied Discount: 500

Compilation Status: Passed


Execution Time:
0.128s

TestCase2:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Applied Discount: 300

Compilation Status: Passed

)
.in
ac
Execution Time:

ty.
rsi
0.12s

n ive
TestCase3: su
tia
lgo

Input:
ga

< hidden >


3@
00

Expected Output:
801

< hidden >


e1
cs

Output:
4s
h.2

Applied Discount: 500


es
m

Compilation Status: Passed


so
h(

Execution Time:
es
m

0.118s
So

TestCase4:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Applied Discount: 400

Compilation Status: Passed


Execution Time:
0.118s

13. Triangle Perimeter Calculator with Abstract Class


Problem Statement:Write a program to calculate the perimeter of a triangle using an
abstract class Shape with abstract method perimeter(). Implement a Triangle class
that overrides the method.

Description:Demonstrates abstract classes, method overriding, and runtime


polymorphism for a triangle.

Input Format:

triangle side1 side2 side3

)
.in
ac
Output Format:

ty.
rsi
Perimeter: <value>

n ive
Sample Input:
su
tia
triangle 3 4 5
lgo
ga
3@

Sample Output:
00

Perimeter: 12
801
e1
cs

Completion Status: Completed


4s
h.2
es

Concepts Included:
m
so

GU 28 3rd Sem Java Prog. Pre-Midterm


h(
es

Language Used: JAVA 8


m
So

Source Code:
import [Link].*;
abstract class Shape{
abstract int perimeter();
}
class Triangle extends Shape{
int l , b, h;
Triangle(int l , int b , int h){
this.l = l;
this.b = b;
this.h = h;
}
@Override
int perimeter(){
return l+b+h;
}
}

class Main{
public static void main(String[] args){
Scanner sc = new Scanner([Link]);
// Read entire line as string
String line = [Link]().trim();
String[] parts = [Link]("\\s+"); // split by spaces
if ([Link] != 4 || !parts[0].equalsIgnoreCase("triangle")) {
[Link]("Invalid input");
[Link]();
return;
}

)
.in
try {

ac
int s1 = [Link](parts[1]);

ty.
int s2 = [Link](parts[2]);

rsi
int s3 = [Link](parts[3]);

ive
Shape triangle = new Triangle(s1, s2, s3);

n
[Link]("Perimeter: " + [Link]());
su
tia
} catch (NumberFormatException e) {
lgo

[Link]("Invalid sides");
}
ga

}
3@

}
00
801

Compilation Details:
e1
cs
4s

TestCase1:
h.2
es

Input:
m
so

< hidden >


h(
es

Expected Output:
m
So

< hidden >

Output:
Perimeter: 24

Compilation Status: Passed


Execution Time:
0.105s

TestCase2:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Perimeter: 18

Compilation Status: Passed


Execution Time:
0.107s

TestCase3:

)
.in
ac
Input:

ty.
rsi
< hidden >

ive
Expected Output:
n
su
tia
< hidden >
lgo

Output:
ga
3@

Perimeter: 29
00
80

Compilation Status: Passed


1
e1

Execution Time:
cs
4s

0.105s
h.2
es
m

TestCase4:
so
h(

Input:
es
m

< hidden >


So

Expected Output:
< hidden >

Output:
Perimeter: 9

Compilation Status: Passed


Execution Time:
0.11s
14. Vehicle Fuel Efficiency with Abstract Class
Problem Statement:Create an abstract class Vehicle with abstract method
fuelEfficiency(). Implement Car and Truck classes with overridden method to
calculate efficiency based on distance and fuel.

Description:Demonstrates abstract classes, runtime polymorphism, and arithmetic


computation.

Input Format:

vehicleType distance fuel

Output Format:

Fuel Efficiency: <value>

)
.in
Sample Input:

ac
ty.
Car 500 25

rsi
ive
Sample Output:
n
su
tia
Fuel Efficiency: 20.0
lgo
ga
3@

Completion Status: Completed


00
80

Concepts Included:
1
e1

GU 28 3rd Sem Java Prog. Pre-Midterm


cs
4s
h.2

Language Used: JAVA 8


es
m
so

Source Code:
h(
es

import [Link].*;
m

// Abstract class
So

abstract class Vehicle {


abstract double fuelEfficiency(double distance, double fuel);
}
// Car class
class Car extends Vehicle {
@Override
double fuelEfficiency(double distance, double fuel) {
return distance / fuel; // km per liter
}
}

// Truck class
class Truck extends Vehicle {
@Override
double fuelEfficiency(double distance, double fuel) {
return distance / (fuel * 1.25); // trucks are less efficient
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String vehicleType = [Link]();
double distance = [Link]();
double fuel = [Link]();
Vehicle vehicle;
if ([Link]("Car")) {
vehicle = new Car();
} else if ([Link]("Truck")) {
vehicle = new Truck();
} else {
[Link]("Invalid vehicle type");

)
.in
[Link]();

ac
return;

ty.
}

rsi
double efficiency = [Link](distance, fuel);

ive
// Print with one decimal place

n
[Link]("Fuel Efficiency: %.1f%n", efficiency);
su
tia
[Link]();
lgo

}
}
ga
3@
00

Compilation Details:
801
e1

TestCase1:
cs
4s

Input:
h.2

< hidden >


es
m

Expected Output:
so
h(

< hidden >


es
m

Output:
So

Fuel Efficiency: 16.0

Compilation Status: Passed


Execution Time:
0.115s

TestCase2:
Input:
< hidden >
Expected Output:
< hidden >

Output:
Fuel Efficiency: 20.0

Compilation Status: Passed


Execution Time:
0.105s

TestCase3:
Input:

)
.in
ac
< hidden >

ty.
rsi
Expected Output:

n ive
< hidden >
su
tia
Output:
lgo
ga

Fuel Efficiency: 16.0


3@

Compilation Status: Passed


00
80

Execution Time:
1
e1

0.103s
cs
4s
h.2

TestCase4:
es
m

Input:
so
h(

< hidden >


es
m

Expected Output:
So

< hidden >

Output:
Fuel Efficiency: 30.0

Compilation Status: Passed


Execution Time:
0.108s

15. Insurance Premium Calculator


Problem Statement:Write a program to calculate the insurance premium for different
types of [Link] program should use an abstract class Insurance with an
abstract method calculatePremium(). Subclasses LifeInsurance, HealthInsurance,
and CarInsurance override this [Link] base premium is entered by the user, and
additional percentage is added depending on the insurance type:

Life Insurance +10%

Health Insurance +20%

Car Insurance +30%

Description:The program should accept insurance type and base premium from the
[Link] should calculate the final premium based on the given [Link] output should
display the insurance type and final premium.

Input Format:

)
.in
A string (insurance type: life/health/car)

ac
ty.
An integer (base premium)

rsi
ive
Output Format:

n
Insurance type su
tia
lgo

Final premium
ga
3@

Sample Input:
00
80

car5000
1
e1
cs

Sample Output:
4s
h.2

Insurance Type: Car InsurancePremium: 6500.0


es
m
so

Completion Status: Completed


h(
es
m

Concepts Included:
So

GU 28 3rd Sem Java Prog. Pre-Midterm

Language Used: JAVA 8

Source Code:
import [Link].*;
// Abstract class
abstract class Insurance {
abstract double calculatePremium(double basePremium);
}
// Life Insurance
class LifeInsurance extends Insurance {
@Override
double calculatePremium(double basePremium) {
return basePremium * 1.10; // +10%

}
}
// Health Insurance
class HealthInsurance extends Insurance {
@Override
double calculatePremium(double basePremium) {
return basePremium * 1.20; // +20%
}
}
// Car Insurance
class CarInsurance extends Insurance {
@Override

)
.in
double calculatePremium(double basePremium) {

ac
return basePremium * 1.30; // +30%

ty.
}

rsi
}

ive
public class Main {

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

String type = [Link]().trim().toLowerCase();


double basePremium = [Link]();
ga

Insurance insurance;
3@

switch (type) {
00

case "life":
80

insurance = new LifeInsurance();


1
e1

[Link]("Insurance Type: Life Insurance");


cs

break;
4s

case "health":
h.2

insurance = new HealthInsurance();


es

[Link]("Insurance Type: Health Insurance");


m

break;
so

case "car":
h(

insurance = new CarInsurance();


es

[Link]("Insurance Type: Car Insurance");


m

break;
So

default:
[Link]("Invalid insurance type");
[Link]();
return;
}
double finalPremium = [Link](basePremium);
// Print with one decimal place
[Link]("Premium: %.1f%n", finalPremium);
[Link]();

}
}

Compilation Details:
TestCase1:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Insurance Type: Life Insurance
Premium: 11000.0

Compilation Status: Passed

)
Execution Time:

.in
ac
0.112s

ty.
rsi
ive
TestCase2:

n
Input: su
tia
lgo

< hidden >


ga
3@

Expected Output:
00

< hidden >


801
e1

Output:
cs
4s

Insurance Type: Health Insurance


h.2

Premium: 2400.0
es

Compilation Status: Passed


m
so

Execution Time:
h(
es

0.104s
m
So

TestCase3:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Insurance Type: Car Insurance
Premium: 6500.0
Compilation Status: Passed
Execution Time:
0.115s

TestCase4:
Input:
< hidden >

Expected Output:
< hidden >

Output:

)
.in
ac
Insurance Type: Life Insurance

ty.
Premium: 2750.0

rsi
ive
Compilation Status: Passed

n
Execution Time: su
tia
lgo

0.112s
ga
3@
00

16. Ticket Booking System


801

Problem Statement:Write a program to calculate the fare of a ticket based on the


e1

travel [Link] program should use an abstract class Ticket with an abstract method
cs

calculateFare(). Subclasses BusTicket, TrainTicket, and FlightTicket override this


4s
h.2

[Link] per km:


es

Bus = 5
m
so

Train = 8
h(
es

Flight = 15
m
So

Description:The program should accept ticket type and distance in [Link]


should calculate and display the fare according to the ticket type.

Input Format:

A string (ticket type: bus/train/flight)

An integer (distance in km)

Output Format:

Ticket type

Fare

Sample Input:
bus120

Sample Output:
Ticket Type: Bus TicketFare: 600

Completion Status: Completed

Concepts Included:
GU 28 3rd Sem Java Prog. Pre-Midterm

Language Used: JAVA 8

)
.in
ac
Source Code:

ty.
rsi
import [Link].*;

ive
// Abstract class

n
abstract class Ticket {
abstract int calculateFare(int distance); su
tia
}
lgo

// Bus Ticket
ga

class BusTicket extends Ticket {


3@

@Override
00

int calculateFare(int distance) {


80

return distance * 5; // Fare per km = 5


1

}
e1
cs

}
4s

// Train Ticket
h.2

class TrainTicket extends Ticket {


@Override
es
m

int calculateFare(int distance) {


so

return distance * 8; // Fare per km = 8


h(

}
es

}
m

// Flight Ticket
So

class FlightTicket extends Ticket {


@Override
int calculateFare(int distance) {
return distance * 15; // Fare per km = 15
}
}

public class Main {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String type = [Link]().trim().toLowerCase();
int distance = [Link]();
Ticket ticket;
switch (type) {
case "bus":
ticket = new BusTicket();
[Link]("Ticket Type: Bus Ticket");
break;
case "train":
ticket = new TrainTicket();
[Link]("Ticket Type: Train Ticket");
break;
case "flight":
ticket = new FlightTicket();
[Link]("Ticket Type: Flight Ticket");
break;
default:
[Link]("Invalid ticket type");
[Link]();
return;
}

)
.in
int fare = [Link](distance);

ac
[Link]("Fare: " + fare);

ty.
[Link]();

rsi
}

ive
}

n
su
tia
Compilation Details:
lgo
ga

TestCase1:
3@
00

Input:
801

< hidden >


e1
cs

Expected Output:
4s
h.2

< hidden >


es
m

Output:
so
h(

Ticket Type: Bus Ticket


es

Fare: 500
m
So

Compilation Status: Passed


Execution Time:
0.115s

TestCase2:
Input:
< hidden >

Expected Output:
< hidden >
Output:
Ticket Type: Train Ticket
Fare: 400

Compilation Status: Passed


Execution Time:
0.107s

TestCase3:
Input:
< hidden >

)
.in
Expected Output:

ac
ty.
< hidden >

rsi
ive
Output:

n
Ticket Type: Flight Ticket su
tia
Fare: 300
lgo
ga

Compilation Status: Passed


3@

Execution Time:
00
80

0.109s
1
e1
cs

TestCase4:
4s
h.2

Input:
es
m

< hidden >


so
h(

Expected Output:
es
m

< hidden >


So

Output:
Ticket Type: Bus Ticket
Fare: 1250

Compilation Status: Passed


Execution Time:
0.107s

17. Multimedia Center with Interfaces (Auto-detection)


Problem Statement:Write a program with two interfaces: AudioPlayer (method
playAudio()) and VideoPlayer (method playVideo()). Implement them in a class
MediaCenter. The program should automatically detect whether the given file is audio
or video based on its extension and simulate playback with realistic quality/
resolution.

Description:This program demonstrates multiple inheritance via interfaces in a


multimedia application. It auto-detects media type from the file extension, avoiding
manual input of “audio” or “video”.

Input Format:

A single line: File name (string with extension)

Output Format:

A message showing detected type and realistic playback simulation.

)
.in
Sample Input:

ac
ty.
song.mp3

rsi
ive
Sample Output:
n
su
tia
Audio file detected: Playing with 128kbps quality
lgo
ga
3@

Completion Status: Completed


00
80

Concepts Included:
1
e1

GU 28 3rd Sem Java Prog. Pre-Midterm


cs
4s
h.2

Language Used: JAVA 8


es
m
so

Source Code:
h(
es

import [Link].*;
m
So

// AudioPlayer interface
interface AudioPlayer {
void playAudio(String fileName);
}
// VideoPlayer interface
interface VideoPlayer {
void playVideo(String fileName);
}
// MediaCenter class implements both interfaces
class MediaCenter implements AudioPlayer, VideoPlayer {
// Supported audio and video extensions
private static final Set<String> audioExt = new HashSet<>([Link]("mp3", "wav",
"aac", "flac"));
private static final Set<String> videoExt = new HashSet<>([Link]("mp4", "avi",
"mkv", "mov"));
@Override
public void playAudio(String fileName) {
[Link]("Audio file detected: Playing with 128kbps quality");
}
@Override
public void playVideo(String fileName) {
[Link]("Video file detected: Playing at 1080p resolution");
}
// Auto-detect method
public void play(String fileName) {
if (![Link](".")) {
[Link]("Unknown file type");
return;
}
String ext = [Link]([Link](".") + 1).toLowerCase();
if ([Link](ext)) {

)
.in
playAudio(fileName);

ac
} else if ([Link](ext)) {

ty.
playVideo(fileName);

rsi
} else {

ive
[Link]("Unknown file type");

n
}
su
tia
}
lgo

}
ga

public class Main {


3@

public static void main(String[] args) {


00

Scanner sc = new Scanner([Link]);


80

String fileName = [Link]().trim();


1
e1

MediaCenter mc = new MediaCenter();


cs

[Link](fileName);
4s
h.2

[Link]();
es

}
m

}
so
h(

Compilation Details:
es
m
So

TestCase1:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Video file detected: Playing at 1080p resolution

Compilation Status: Passed


Execution Time:
0.091s

TestCase2:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Audio file detected: Playing with 128kbps quality

)
.in
ac
Compilation Status: Passed

ty.
rsi
Execution Time:

n ive
0.087s
su
tia
lgo

TestCase3:
ga

Input:
3@
00

< hidden >


801

Expected Output:
e1
cs

< hidden >


4s
h.2

Output:
es
m

Video file detected: Playing at 1080p resolution


so
h(

Compilation Status: Passed


es
m

Execution Time:
So

0.096s

TestCase4:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Video file detected: Playing at 1080p resolution
Compilation Status: Passed
Execution Time:
0.09s

18. Shopping Cart System


Problem Statement:Write a program to simulate a simple shopping cart system using
multiple inheritance with interfaces.

Create an interface AddToCart with a method addItem(String item).

Create another interface Payment with a method makePayment().

Create a class ShoppingCart that implements both.

)
.in
Description:

ac
ty.
User first adds one or more items to the cart using the add command.

rsi
ive
When the user types pay, the system processes the payment and shows how many

n
items were purchased.
su
tia
Input Format:
lgo
ga

First input: add <item> (to add an item).


3@

Then: pay (to make the payment).


00
80

Output Format:
1
e1

Confirmation of item addition.


cs
4s

Payment success message with item count.


h.2
es
m

Sample Input:
so
h(

add Laptoppay
es
m

Sample Output:
So

Item added: LaptopPayment successful for 1 items.

Completion Status: Completed

Concepts Included:
GU 28 3rd Sem Java Prog. Pre-Midterm

Language Used: JAVA 8

Source Code:
import [Link].*;
// Interface for adding items
interface AddToCart {
void addItem(String item);
}
// Interface for payment
interface Payment {
void makePayment();
}
// ShoppingCart implements both interfaces
class ShoppingCart implements AddToCart, Payment {
private List<String> items;
ShoppingCart() {
items = new ArrayList<>();
}
@Override

)
.in
public void addItem(String item) {

ac
[Link](item);

ty.
[Link]("Item added: " + item);

rsi
}

ive
@Override

n
public void makePayment() {
su
tia
[Link]("Payment successful for " + [Link]() + " items.");
lgo

}
}
ga
3@

public class Main {


00

public static void main(String[] args) {


80

Scanner sc = new Scanner([Link]);


1
e1

ShoppingCart cart = new ShoppingCart();


cs

while ([Link]()) {
4s

String input = [Link]().trim();


h.2

if ([Link]("pay")) {
es

[Link]();
m

break; // Exit after payment


so

} else if ([Link]().startsWith("add ")) {


h(

String item = [Link](4).trim(); // Get item name


es

[Link](item);
m

} else {
So

[Link]("Invalid command");
}
}
}
}

Compilation Details:

TestCase1:
Input:
< hidden >
Expected Output:
< hidden >

Output:
Item added: Mobile
Payment successful for 1 items.

Compilation Status: Passed


Execution Time:
0.111s

TestCase2:

)
.in
Input:

ac
ty.
< hidden >

rsi
ive
Expected Output:

n
< hidden > su
tia
lgo

Output:
ga
3@

Item added: Book


Payment successful for 1 items.
00
80

Compilation Status: Passed


1
e1
cs

Execution Time:
4s
h.2

0.115s
es
m

TestCase3:
so
h(

Input:
es
m

< hidden >


So

Expected Output:
< hidden >

Output:
Item added: Shoes
Payment successful for 1 items.

Compilation Status: Passed


Execution Time:
0.103s
TestCase4:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Item added: Bag
Payment successful for 1 items.

Compilation Status: Passed

)
Execution Time:

.in
ac
0.108s

ty.
rsi
ive
19. Student Result Evaluation
n
su
tia
Problem Statement:Write a program that evaluates whether a student passes or fails
lgo

based on marks and attendance. The program should use multiple inheritance with
ga

interfaces.
3@

Define an interface Marks with method enterMarks(int marks).


00
80

Define an interface Attendance with method enterAttendance(int attendance).


1
e1

Implement both interfaces in the Student class and provide a method checkResult()
cs

that checks:
4s
h.2

Marks must be ≥ 40
es
m

Attendance must be ≥ 75%


so
h(

If both conditions are met, display "Result: Pass", otherwise "Result: Fail".
es
m

Description:
So

The program accepts marks and attendance percentage as input.

Uses multiple inheritance (via interfaces).

Evaluates and prints result.

Input Format:

First line Marks (integer)

Second line Attendance percentage (integer)

Output Format:

"Result: Pass" or "Result: Fail"


Sample Input:
5580

Sample Output:
Result: Pass

Completion Status: Completed

Concepts Included:
GU 28 3rd Sem Java Prog. Pre-Midterm

)
.in
Language Used: JAVA 8

ac
ty.
rsi
Source Code:

n ive
import [Link].*;
interface Marks{ su
tia
public void enterMarks(int marks);
lgo

}
ga
3@

interface Attendance{
00

public void enterAttendance(int attendance);


80

}
1

class Student implements Marks,Attendance{


e1

private int marks;


cs

private int attendance;


4s
h.2

@Override
public void enterMarks(int marks) {
es

[Link] = marks;
m
so

}
h(

@Override
es

public void enterAttendance(int attendance) {


m

[Link] = attendance;
So

}
void checkResult(){
if(marks>=40 && attendance >= 75){
[Link]("Result: Pass");
}else{
[Link]("Result: Fail");
}
}
}
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner([Link]);
Student s = new Student();
int marks = [Link]();
int attendance = [Link]();
[Link](marks);
[Link](attendance);
[Link]();
}
}

Compilation Details:

TestCase1:
Input:
< hidden >

Expected Output:

)
.in
< hidden >

ac
ty.
Output:

rsi
ive
Result: Pass

n
Compilation Status: Passed su
tia
lgo

Execution Time:
ga
3@

0.101s
00
80

TestCase2:
1
e1

Input:
cs
4s

< hidden >


h.2
es

Expected Output:
m
so

< hidden >


h(
es

Output:
m
So

Result: Fail

Compilation Status: Passed


Execution Time:
0.092s

TestCase3:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Result: Fail

Compilation Status: Passed


Execution Time:
0.099s

TestCase4:
Input:
< hidden >

)
.in
ac
Expected Output:

ty.
rsi
< hidden >

ive
Output:
n
su
tia
Result: Pass
lgo

Compilation Status: Passed


ga
3@

Execution Time:
00
80

0.092s
1
e1
cs
4s

20. Library Management System


h.2
es

Problem Statement:Create two interfaces: BookOperations (methods addBook(String


m

book)) and UserOperations (methods borrowBook(String book)).A class Library


so

implements both.
h(
es

Description:
m
So

The user first adds a book.

Another user borrows the book.

If the book is available, borrowing succeeds. Otherwise, a message should display


"Book not available".

Input Format:

First line: Book name to add.

Second line: A command in the format: borrow <bookName>

Output Format:

Messages confirming whether the book was added or borrowed successfully.


Sample Input:
JavaProgrammingborrow JavaProgramming

Sample Output:
Book added: JavaProgrammingBook borrowed: JavaProgramming

Completion Status: Completed

Concepts Included:
GU 28 3rd Sem Java Prog. Pre-Midterm

)
.in
Language Used: JAVA 8

ac
ty.
rsi
Source Code:

n ive
import [Link].*;
// Interface for book operations su
tia
interface BookOperations {
lgo

void addBook(String book);


ga

}
3@

// Interface for user operations


00

interface UserOperations {
80

void borrowBook(String book);


1

}
e1

// Library class implements both interfaces


cs

class Library implements BookOperations, UserOperations {


4s
h.2

private Set<String> books;


Library() {
es

books = new HashSet<>();


m
so

}
h(

@Override
es

public void addBook(String book) {


m

[Link](book);
So

[Link]("Book added: " + book);


}
@Override
public void borrowBook(String book) {
if ([Link](book)) {
[Link](book);
[Link]("Book borrowed: " + book);
} else {
[Link]("Book not available");
}
}
}

public class Main {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String bookToAdd = [Link]().trim();
String borrowCommand = [Link]().trim();
Library library = new Library();
[Link](bookToAdd);
if ([Link]().startsWith("borrow ")) {
String bookToBorrow = [Link](7).trim();
[Link](bookToBorrow);
} else {

[Link]("Invalid command");
}
}
}

Compilation Details:

)
.in
ac
ty.
TestCase1:

rsi
ive
Input:

n
< hidden > su
tia
lgo

Expected Output:
ga
3@

< hidden >


00

Output:
801
e1

Book added: PythonBasics


cs

Book not available


4s
h.2

Compilation Status: Passed


es

Execution Time:
m
so

0.093s
h(
es
m

TestCase2:
So

Input:
< hidden >

Expected Output:
< hidden >

Output:
Book added: DataStructures
Book borrowed: DataStructures

Compilation Status: Passed


Execution Time:
0.099s

TestCase3:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Book added: OOPConcepts

)
.in
Book not available

ac
ty.
Compilation Status: Passed

rsi
ive
Execution Time:

n
0.102s su
tia
lgo

TestCase4:
ga
3@

Input:
00
80

< hidden >


1
e1

Expected Output:
cs
4s

< hidden >


h.2
es

Output:
m
so

Book added: MachineLearning


h(

Book borrowed: MachineLearning


es
m

Compilation Status: Passed


So

Execution Time:
0.096s

21. Multimedia Center with Interfaces (Auto-detection)


Problem Statement:Write a program with two interfaces: AudioPlayer (method
playAudio()) and VideoPlayer (method playVideo()). Implement them in a class
MediaCenter. The program should automatically detect whether the given file is audio
or video based on its extension and simulate playback with realistic quality/
resolution.

Description:This program demonstrates multiple inheritance via interfaces in a


multimedia application. It auto-detects media type from the file extension, avoiding
manual input of “audio” or “video”.

Input Format:

A single line: File name (string with extension)

Output Format:

A message showing detected type and realistic playback simulation.

Sample Input:
song.mp3

Sample Output:

)
.in
Audio file detected: Playing with 128kbps quality

ac
ty.
rsi
ive
Completion Status: Completed

n
su
tia
Concepts Included:
lgo

GU 28 3rd Sem Java Prog. Pre-Midterm


ga
3@
00

Language Used: JAVA 8


801
e1

Source Code:
cs
4s

import [Link].*;
h.2

// Interface for audio playback


es

interface AudioPlayer {
m

void playAudio(String fileName);


so

}
h(

// Interface for video playback


es

interface VideoPlayer {
m

void playVideo(String fileName);


So

}
// MediaCenter class implements both interfaces
class MediaCenter implements AudioPlayer, VideoPlayer {
// Supported audio and video extensions
private static final Set<String> audioExt = new HashSet<>([Link]("mp3", "wav",
"aac", "flac"));
private static final Set<String> videoExt = new HashSet<>([Link]("mp4", "avi",
"mkv", "mov"));
@Override
public void playAudio(String fileName) {
[Link]("Audio file detected: Playing with 128kbps quality");
}
@Override
public void playVideo(String fileName) {
[Link]("Video file detected: Playing at 1080p resolution");
}

// Auto-detect file type


public void play(String fileName) {
if (![Link](".")) {
[Link]("Unknown file type");
return;
}
String ext = [Link]([Link](".") + 1).toLowerCase();
if ([Link](ext)) {
playAudio(fileName);
} else if ([Link](ext)) {
playVideo(fileName);
} else {
[Link]("Unknown file type");
}

)
.in
}

ac
}

ty.
public class Main {

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

ive
Scanner sc = new Scanner([Link]);

n
String fileName = [Link]().trim();
su
tia
MediaCenter mc = new MediaCenter();
lgo

[Link](fileName);
}
ga

}
3@
00
80

Compilation Details:
1
e1
cs

TestCase1:
4s
h.2

Input:
es
m

< hidden >


so
h(

Expected Output:
es
m

< hidden >


So

Output:
Video file detected: Playing at 1080p resolution

Compilation Status: Passed


Execution Time:
0.087s

TestCase2:
Input:
< hidden >
Expected Output:
< hidden >

Output:
Audio file detected: Playing with 128kbps quality

Compilation Status: Passed


Execution Time:
0.093s

TestCase3:
Input:

)
.in
ac
< hidden >

ty.
rsi
Expected Output:

n ive
< hidden >
su
tia
Output:
lgo
ga

Video file detected: Playing at 1080p resolution


3@

Compilation Status: Passed


00
80

Execution Time:
1
e1

0.088s
cs
4s
h.2

TestCase4:
es
m

Input:
so
h(

< hidden >


es
m

Expected Output:
So

< hidden >

Output:
Video file detected: Playing at 1080p resolution

Compilation Status: Passed


Execution Time:
0.09s

22. User Defined Exception – Password Validation


Problem Statement:Create a WeakPasswordException.

Description:A password must be at least 6 characters. If not, throw exception.

Input Format:Password string.

Output Format:“Valid Password” or Exception message.

Sample Input:
abc

Sample Output:
Weak Password: Must be at least 6 characters

)
.in
ac
Completion Status: Completed

ty.
rsi
Concepts Included:

n ive
GU 28 3rd Sem Java Prog. Pre-Midterm su
tia
lgo

Language Used: JAVA 8


ga
3@

Source Code:
00
80

import [Link].*;
1
e1

// Custom Exception
cs

class WeakPasswordException extends Exception {


4s

WeakPasswordException(String message) {
h.2

super(message);
es

}
m

}
so

public class Main {


h(

public static void main(String[] args) {


es

Scanner sc = new Scanner([Link]);


m
So

String password = [Link]().trim();


try {
validatePassword(password);
[Link]("Valid Password");
} catch (WeakPasswordException e) {
[Link]([Link]());
}
[Link]();
}

// Method to validate password


static void validatePassword(String password) throws WeakPasswordException {
if ([Link]() < 6) {
throw new WeakPasswordException("Weak Password: Must be at least 6
characters");
}
}
}

Compilation Details:

TestCase1:
Input:
< hidden >

Expected Output:
< hidden >

)
.in
Output:

ac
ty.
Valid Password

rsi
ive
Compilation Status: Passed

n
Execution Time: su
tia
lgo

0.091s
ga
3@

TestCase2:
00
80

Input:
1
e1

< hidden >


cs
4s

Expected Output:
h.2
es

< hidden >


m
so

Output:
h(
es

Weak Password: Must be at least 6 characters


m
So

Compilation Status: Passed


Execution Time:
0.092s

TestCase3:
Input:
< hidden >

Expected Output:
< hidden >
Output:
Valid Password

Compilation Status: Passed


Execution Time:
0.091s

TestCase4:
Input:
< hidden >

Expected Output:

)
.in
ac
< hidden >

ty.
rsi
Output:

n ive
Valid Password
su
tia
Compilation Status: Passed
lgo
ga

Execution Time:
3@

0.091s
00
801
e1

23. Custom Exception for Invalid Age


cs
4s

Problem Statement:Write a program that defines a user-defined exception


h.2

InvalidAgeException. The program should read a person’s age and throw the
es

exception if the age is below 18. Otherwise, print "Eligible to Vote".


m
so

Description:Demonstrates custom exception class extending Exception and using


h(

throw and catch.


es
m

Input Format:
So

A single integer (age)

Output Format:

"Eligible to Vote" or "Invalid Age: must be 18 or above"

Sample Input:
16

Sample Output:
Invalid Age: must be 18 or above
Completion Status: Completed

Concepts Included:
GU 28 3rd Sem Java Prog. Pre-Midterm

Language Used: JAVA 8

Source Code:
import [Link].*;
class InvalidAgeException extends Exception {
public InvalidAgeException (String message){
super(message);
}

)
.in
}

ac
public class Main {

ty.
public static void main(String[] args){

rsi
Scanner sc = new Scanner([Link]);

ive
try{

n
// User-Define Exception su
tia
int age = [Link]();
lgo

if(age < 18){


ga

throw new InvalidAgeException ("Invalid Age: must be 18 or above");


3@

}else{
[Link]("Eligible to Vote");
00
80

}
1

}catch(InvalidAgeException e){
e1

[Link]([Link]());
cs

}
4s

}
h.2

}
es
m
so

Compilation Details:
h(
es
m

TestCase1:
So

Input:
< hidden >

Expected Output:
< hidden >

Output:
Eligible to Vote

Compilation Status: Passed


Execution Time:
0.094s

TestCase2:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Eligible to Vote

Compilation Status: Passed

)
.in
ac
Execution Time:

ty.
rsi
0.09s

n ive
TestCase3: su
tia
lgo

Input:
ga

< hidden >


3@
00

Expected Output:
801

< hidden >


e1
cs

Output:
4s
h.2

Invalid Age: must be 18 or above


es
m

Compilation Status: Passed


so
h(

Execution Time:
es
m

0.09s
So

TestCase4:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Eligible to Vote

Compilation Status: Passed


Execution Time:
0.093s

24. ATM Transaction with Exception Hierarchy


Problem Statement:Create a program to simulate an ATM. It should handle
InvalidPINException and InsufficientBalanceException using exception hierarchy.

Description:Demonstrates user-defined exceptions, inheritance, and structured


handling.

Input Format:

First line: PIN

)
.in
Second line: withdrawal amount

ac
Output Format:

ty.
rsi
Balance after withdrawal or exception message

n ive
Sample Input: su
tia
lgo

12342000
ga
3@

Sample Output:
00
80

Insufficient balance!
1
e1
cs
4s

Completion Status: Completed


h.2
es

Concepts Included:
m
so
h(

GU 28 3rd Sem Java Prog. Pre-Midterm


es
m

Language Used: JAVA 8


So

Source Code:
import [Link].*;

class ATMException extends Exception {


ATMException(String msg) { super(msg); }
}

class InvalidPINException extends ATMException {


InvalidPINException(String msg) { super(msg); }
}

class InsufficientBalanceException extends ATMException {


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

public class Main {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int pin = [Link]();
int amount = [Link]();
int balance = 1000;

try {
if(pin != 1111) throw new InvalidPINException("Invalid PIN!");
if(amount > balance) throw new InsufficientBalanceException("Insufficient balance!");
balance -= amount;
[Link]("Balance: " + balance);
} catch(ATMException e) {

)
.in
[Link]([Link]());

ac
}

ty.
}

rsi
}

n ive
Compilation Details: su
tia
lgo

TestCase1:
ga
3@

Input:
00
80

< hidden >


1
e1

Expected Output:
cs
4s

< hidden >


h.2
es

Output:
m
so

Invalid PIN!
h(
es

Compilation Status: Passed


m
So

Execution Time:
0.089s

TestCase2:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Insufficient balance!

Compilation Status: Passed


Execution Time:
0.093s

TestCase3:
Input:
< hidden >

Expected Output:
< hidden >

)
.in
ac
Output:

ty.
rsi
Balance: 500

ive
Compilation Status: Passed
n
su
tia
Execution Time:
lgo
ga

0.106s
3@
00

TestCase4:
801

Input:
e1
cs

< hidden >


4s
h.2

Expected Output:
es
m

< hidden >


so
h(

Output:
es
m

Balance: 0
So

Compilation Status: Passed


Execution Time:
0.108s

25. Intersection of Two SetsProblem Statement:Find the


intersection of two sets of integers.
Description:You need to read two sets of integers from the user and print their
intersection. Use Java's Set interface and its operations to achieve this.

Input Format:
The first line contains an integer, n (1 ≤ n ≤ 100), denoting the number of elements in
the first [Link] second line contains n space-separated [Link] third line
contains an integer, m (1 ≤ m ≤ 100), denoting the number of elements in the second
[Link] fourth line contains m space-separated [Link] Format:

Print the elements in the intersection of the two sets, one per line. If there are no
common elements, print "No common elements."

Sample Input:41 2 3 433 4 5

Sample Output:34

Completion Status: Completed

Concepts Included:

)
.in
ac
GU 28 3rd Sem Java Prog. Pre-Midterm

ty.
rsi
Language Used: JAVA 8

n ive
Source Code: su
tia
lgo

import [Link].*;
ga
3@

public class Main {


00

public static void main(String[] args) {


80

Scanner sc = new Scanner([Link]);


1
e1

// Read first set


cs

int n = [Link]();
4s
h.2

Set<Integer> set1 = new HashSet<>();


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

[Link]([Link]());
m
so

}
h(
es

// Read second set


m

int m = [Link]();
So

Set<Integer> set2 = new HashSet<>();


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

// Find intersection
[Link](set2);

// Output result
if ([Link]()) {
[Link]("No common elements");
} else {
List<Integer> result = new ArrayList<>(set1);
[Link](result);
for (int num : result) {
[Link](num);
}
}
}
}

Compilation Details:

TestCase1:
Input:
< hidden >

Expected Output:

)
.in
< hidden >

ac
ty.
Output:

rsi
ive
3

n
4
5 su
tia
lgo

Compilation Status: Passed


ga
3@

Execution Time:
00
80

0.093s
1
e1
cs

TestCase2:
4s
h.2

Input:
es

< hidden >


m
so

Expected Output:
h(
es

< hidden >


m
So

Output:
200

Compilation Status: Passed


Execution Time:
0.093s

TestCase3:
Input:
< hidden >
Expected Output:
< hidden >

Output:
10
30

Compilation Status: Passed


Execution Time:
0.091s

TestCase4:

)
.in
Input:

ac
ty.
< hidden >

rsi
ive
Expected Output:

n
< hidden > su
tia
lgo

Output:
ga
3@

No common elements
00

Compilation Status: Passed


801
e1

Execution Time:
cs
4s

0.092s
h.2
es
m

26. Summing Values in a MapProblem Statement:Given a list of


so

key-value pairs, sum the values for each unique key.


h(
es

Description:You need to read a list of key-value pairs from the user and calculate the
m

sum of values for each unique key. Use Java's Map interface to store the key-value
So

pairs and perform the sum operation.

Input Format:

The first line contains an integer, n (1 ≤ n ≤ 100), denoting the number of key-value
[Link] next n lines each contain a key (string) and a value (integer).Output Format:

Print each unique key and its summed value, one per line.

Sample Input:4apple 10banana 5apple 20banana 15

Sample Output:banana 20apple 30

Completion Status: Completed


Concepts Included:
GU 28 3rd Sem Java Prog. Pre-Midterm

Language Used: JAVA 8

Source Code:
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
Map<String, Integer> map = new LinkedHashMap<>(); // maintain insertion order
for (int i = 0; i < n; i++) {

)
String key = [Link]();

.in
ac
int value = [Link]();

ty.
// Sum values for the same key

rsi
[Link](key, [Link](key, 0) + value);

ive
}

n
// Print each key and summed value
su
for ([Link]<String, Integer> entry : [Link]()) {
tia
[Link]([Link]() + " " + [Link]());
lgo

}
ga

[Link]();
3@

}
00

}
801
e1

Compilation Details:
cs
4s
h.2

TestCase1:
es

Input:
m
so
h(

< hidden >


es

Expected Output:
m
So

< hidden >

Output:
apple 30
banana 15
orange 15

Compilation Status: Passed


Execution Time:
0.121s

TestCase2:
Input:
< hidden >

Expected Output:
< hidden >

Output:
red 10
blue 4
green 7

Compilation Status: Passed


Execution Time:

)
.in
0.129s

ac
ty.
rsi
TestCase3:

n ive
Input:
su
tia
< hidden >
lgo
ga

Expected Output:
3@

< hidden >


00
80

Output:
1
e1
cs

book 1
4s

pen 2
h.2

Compilation Status: Passed


es
m

Execution Time:
so
h(

0.112s
es
m
So

TestCase4:
Input:
< hidden >

Expected Output:
< hidden >

Output:
cat 10
dog 8

Compilation Status: Passed


Execution Time:
0.113s

27. Creating a Frequency MapProblem Statement:Read a list of


words and create a frequency map of each word.
Description:You need to read a list of words from the user and create a map where
the keys are the words and the values are their respective frequencies. Use Java's
Map interface to store and calculate the frequencies.

Input Format:

The first line contains an integer, n (1 ≤ n ≤ 100), denoting the number of [Link]
second line contains n space-separated [Link] Format:

)
.in
Print each word and its frequency, one per line.

ac
ty.
Sample Input:4apple banana apple grape

rsi
ive
Sample Output:banana 1apple 2grape 1

n
su
tia

Completion Status: Completed


lgo
ga
3@

Concepts Included:
00
80

GU 28 3rd Sem Java Prog. Pre-Midterm


1
e1
cs

Language Used: JAVA 8


4s
h.2

Source Code:
es
m

import [Link].*;
so

public class Main {


h(

public static void main(String[] args) {


es

Scanner sc = new Scanner([Link]);


m
So

int n = [Link]();
Map<String, Integer> freqMap = new LinkedHashMap<>(); // preserve insertion order

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


String word = [Link]();
[Link](word, [Link](word, 0) + 1);
}
// Print word frequencies
for ([Link]<String, Integer> entry : [Link]()) {
[Link]([Link]() + " " + [Link]());
}
[Link]();
}
}
Compilation Details:

TestCase1:
Input:
< hidden >

Expected Output:
< hidden >

Output:
cat 3
dog 1

)
.in
Compilation Status: Passed

ac
ty.
Execution Time:

rsi
ive
0.111s

n
su
tia
TestCase2:
lgo
ga

Input:
3@

< hidden >


00
80

Expected Output:
1
e1

< hidden >


cs
4s

Output:
h.2
es

dog 3
m

cat 1
so

fish 1
h(
es

Compilation Status: Passed


m
So

Execution Time:
0.107s

TestCase3:
Input:
< hidden >

Expected Output:
< hidden >

Output:
red 2
blue 1

Compilation Status: Passed


Execution Time:
0.124s

TestCase4:
Input:
< hidden >

Expected Output:

)
.in
< hidden >

ac
ty.
Output:

rsi
ive
pen 3

n
pencil 2
marker 1 su
tia
lgo

Compilation Status: Passed


ga
3@

Execution Time:
00

0.111s
801
e1
cs

28. Removing Duplicates from a List


4s
h.2

Problem Statement:Write a Java program to remove duplicates from a given list of


es

integers while preserving the order of elements.


m
so

Description:You are given a list of integers. Your task is to write a Java program that
h(

removes duplicate elements from the list while maintaining the original order of
es

elements. The program should read the list of integers from the user, process it to
m

remove duplicates, and then output the modified list.


So

Input Format:

The first line contains an integer n, representing the number of elements in the
[Link] next n lines each contain one integer, representing elements of the [Link]
Format:

Output the modified list after removing duplicates, each element in a new line.

Sample Input:71232431

Sample Output:1234

Completion Status: Completed


Concepts Included:
GU 28 3rd Sem Java Prog. Pre-Midterm

Language Used: JAVA 8

Source Code:
import [Link].*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner([Link]);
int n = [Link]();
List<Integer> list = new ArrayList<>();
for(int i = 0 ; i < n ; i++){

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

.in
ac
}

ty.
Set <Integer> set = new LinkedHashSet<>(list);

rsi
for (int num : set) {

ive
[Link](num);

n
}
} su
tia
}
lgo
ga
3@

Compilation Details:
00
80

TestCase1:
1
e1

Input:
cs
4s

< hidden >


h.2
es

Expected Output:
m
so

< hidden >


h(
es

Output:
m
So

1
2
3
4
5

Compilation Status: Passed


Execution Time:
0.099s

TestCase2:
Input:
< hidden >

Expected Output:
< hidden >

Output:
1
2
3

Compilation Status: Passed


Execution Time:
0.091s

)
.in
ac
TestCase3:

ty.
rsi
Input:

n ive
< hidden >
su
tia
Expected Output:
lgo
ga

< hidden >


3@

Output:
00
80

1
1
e1

Compilation Status: Passed


cs
4s

Execution Time:
h.2
es

0.099s
m
so
h(
es

29. Generic Maximum Finder


m
So

Problem Statement:Write a program that defines a generic class MaxFinder<T


extends Comparable<T>> to find the maximum element in a list of numbers or
strings.

Description:

Implement a method findMax(List<T> list) that returns the maximum element.

The class should work with integers, doubles, and strings.

Input Format:

First line: number of elements n

Next n lines: elements (either integers, doubles, or strings)

Output Format:
The maximum element

Sample Input:
523 78 45 12 89

Sample Output:
Maximum: 89

Completion Status: Completed

Concepts Included:

)
.in
GU 28 3rd Sem Java Prog. Pre-Midterm

ac
ty.
rsi
Language Used: JAVA 8

n ive
Source Code: su
tia
lgo

import [Link].*;
// Generic class to find maximum
ga

class MaxFinder<T extends Comparable<T>> {


3@

public T findMax(List<T> list) {


00

if (list == null || [Link]()) {


80

return null;
1
e1

}
cs

T max = [Link](0);
4s

for (T item : list) {


h.2

if ([Link](max) > 0) {
es

max = item;
m

}
so

}
h(
es

return max;
m

}
So

}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
List<Integer> intList = new ArrayList<>();
for (int i = 0; i < n; i++) {
[Link]([Link]());
}
MaxFinder<Integer> finder = new MaxFinder<>();
[Link]("Maximum: " + [Link](intList));
[Link]();
}
}
Compilation Details:

TestCase1:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Maximum: 30

Compilation Status: Passed

)
.in
ac
Execution Time:

ty.
rsi
0.098s

n ive
TestCase2: su
tia
lgo

Input:
ga
3@

< hidden >


00

Expected Output:
801

< hidden >


e1
cs

Output:
4s
h.2

Maximum: -3
es
m

Compilation Status: Passed


so
h(

Execution Time:
es
m

0.094s
So

TestCase3:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Maximum: 200

Compilation Status: Passed


Execution Time:
0.099s

TestCase4:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Maximum: 35

)
.in
ac
Compilation Status: Passed

ty.
rsi
Execution Time:

n ive
0.101s
su
tia
lgo

30. Sort Utility


ga
3@

Problem Statement:Write a program with a generic method sortList(List<T>) that


00

sorts any list of objects (integers, doubles, strings) using Collections.


801

Description:
e1
cs

Implement a static generic method with bounded type <T extends Comparable<T>>.
4s
h.2

Sort and print the elements in ascending order.


es

Input Format:
m
so

First line: number of elements n


h(
es

Next n elements
m
So

Output Format:

Sorted list

Sample Input:
5banana apple mango cherry grape

Sample Output:
apple banana cherry grape mango

Completion Status: Completed


Concepts Included:
GU 28 3rd Sem Java Prog. Pre-Midterm

Language Used: JAVA 8

Source Code:
import [Link].*;

public class Main {

public static <T extends Comparable<T>> void sortList(List<T> list) {


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

)
[Link]([Link](i));

.in
ac
if (i != [Link]() - 1) {

ty.
[Link](" ");

rsi
}

ive
}

n
[Link]();
} su
tia
lgo

public static void main(String[] args) {


ga

Scanner sc = new Scanner([Link]);


3@

int n = [Link]();
00

List<String> list = new ArrayList<>();


80

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


1

[Link]([Link]());
e1

}
cs
4s

sortList(list);
h.2

}
}
es
m
so

Compilation Details:
h(
es
m

TestCase1:
So

Input:
< hidden >

Expected Output:
< hidden >

Output:
apple banana kiwi mango orange zebra

Compilation Status: Passed


Execution Time:
0.096s

TestCase2:
Input:
< hidden >

Expected Output:
< hidden >

Output:
apple banana peach

Compilation Status: Passed

)
.in
ac
Execution Time:

ty.
rsi
0.088s

n ive
TestCase3: su
tia
lgo

Input:
ga

< hidden >


3@
00

Expected Output:
801

< hidden >


e1
cs

Output:
4s
h.2

blue green indigo orange red violet yellow


es
m

Compilation Status: Passed


so
h(

Execution Time:
es
m

0.092s
So

31. Stack Implementation


Problem Statement:Write a program to implement a generic stack class using
ArrayList<T>. The stack should support the basic operations: push, pop, and peek.

Description:

Create a generic class GenericStack<T>.

The class should allow storing integers, strings, or doubles.

Implement methods push(T item), pop(), and peek().

If the stack is empty during pop or peek, handle it gracefully.


Input Format:

Each line contains a command:

push <value> pushes a value

pop pops the top element

peek shows the top element

Output Format:

Output messages for each operation

Sample Input:
4push 10push 20poppeek

)
.in
ac
Sample Output:

ty.
rsi
Pushed: 10Pushed: 20Popped: 20Peek: 10

n ive
su
tia
Completion Status: Completed
lgo
ga

Concepts Included:
3@
00

GU 28 3rd Sem Java Prog. Pre-Midterm


801
e1

Language Used: JAVA 8


cs
4s

Source Code:
h.2
es

import [Link].*;
m
so

class GenericStack<T> {
h(

private ArrayList<T> stack;


es
m

public GenericStack() {
So

stack = new ArrayList<>();


}
// Push an element
public void push(T item) {
[Link](item);
[Link]("Pushed: " + item);
}
// Pop an element
public void pop() {
if ([Link]()) {
[Link]("Stack is empty");
} else {
T item = [Link]([Link]() - 1);
[Link]("Popped: " + item);
}
}
// Peek top element
public void peek() {
if ([Link]()) {
[Link]("Stack is empty");
} else {
T item = [Link]([Link]() - 1);
[Link]("Peek: " + item);
}
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
[Link](); // consume newline

)
.in
GenericStack<String> stack = new GenericStack<>();

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

ty.
String line = [Link]();

rsi
String[] parts = [Link](" ", 2);

n ive
switch (parts[0]) {
su
tia
case "push":
lgo

[Link](parts[1]);
break;
ga

case "pop":
3@

[Link]();
00

break;
80

case "peek":
1
e1

[Link]();
cs

break;
4s

default:
h.2

[Link]("Invalid command");
es

}
m

}
so

[Link]();
h(

}
es

}
m
So

Compilation Details:

TestCase1:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Pushed: apple
Pushed: banana
Peek: banana

Compilation Status: Passed


Execution Time:
0.106s

TestCase2:
Input:
< hidden >

Expected Output:

)
.in
< hidden >

ac
ty.
Output:

rsi
ive
Pushed: A

n
Pushed: B
Pushed: C su
tia
Popped: C
lgo

Peek: B
ga
3@

Compilation Status: Passed


00
80

Execution Time:
1
e1

0.102s
cs
4s
h.2

TestCase3:
es

Input:
m
so
h(

< hidden >


es

Expected Output:
m
So

< hidden >

Output:
Pushed: dog
Pushed: cat
Peek: cat
Popped: cat

Compilation Status: Passed


Execution Time:
0.102s
TestCase4:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Pushed: 100
Pushed: 200
Popped: 200

Compilation Status: Passed

)
.in
Execution Time:

ac
ty.
0.097s

rsi
n ive
32. Frequency Counter su
tia
lgo

Problem Statement:Write a program with a generic method to count the frequency of


ga

elements in a list using a HashMap.


3@

Description:
00
80

The program should accept n elements of any type (string or integer).


1
e1

Implement a method countFrequency(List<T> list) to count and print the frequency of


cs

each element.
4s
h.2

Use a HashMap<T, Integer> to store frequency counts.


es
m

Input Format:
so
h(

First line: integer n number of elements


es
m

Second line: n space-separated elements


So

Output Format:

Each unique element with its frequency

Sample Input:
8apple mango apple orange mango apple grape mango

Sample Output:
apple -> 3mango -> 3orange -> 1grape -> 1

Completion Status: Completed


Concepts Included:
GU 28 3rd Sem Java Prog. Pre-Midterm

Language Used: JAVA 8

Source Code:
import [Link].*;

public class Main {

// Generic method to count frequency using HashMap


public static <T> void countFrequency(List<T> list) {
Map<T, Integer> frequencyMap = new HashMap<>();

)
.in
ac
for (T item : list) {

ty.
[Link](item, [Link](item, 0) + 1);

rsi
}

n ive
for ([Link]<T, Integer> entry : [Link]()) {
su
[Link]([Link]() + " -> " + [Link]());
tia
}
lgo

}
ga
3@

public static void main(String[] args) {


00

Scanner sc = new Scanner([Link]);


80

int n = [Link]();
1

[Link](); // consume newline


e1
cs
4s

String line = [Link]();


h.2

String[] tokens = [Link](" ");


es
m

// Assume elements are strings, but works generically


so

List<String> list = [Link](tokens);


h(
es

countFrequency(list);
m

}
So

Compilation Details:

TestCase1:
Input:
< hidden >

Expected Output:
< hidden >

Output:
1 -> 2
2 -> 2
3 -> 1

Compilation Status: Passed


Execution Time:
0.112s

TestCase2:
Input:
< hidden >

Expected Output:

)
.in
ac
< hidden >

ty.
rsi
Output:

n ive
cat -> 2
dog -> 3 su
tia
lion -> 1
lgo
ga

Compilation Status: Passed


3@
00

Execution Time:
80

0.119s
1
e1
cs
4s

TestCase3:
h.2

Input:
es
m

< hidden >


so
h(

Expected Output:
es
m

< hidden >


So

Output:
A -> 4

Compilation Status: Passed


Execution Time:
0.117s

TestCase4:
Input:
< hidden >

Expected Output:
< hidden >

Output:
red -> 3
green -> 2
blue -> 2

Compilation Status: Passed


Execution Time:
0.096s

)
.in
ac
ty.
33. Sum of Generic Numbers

rsi
ive
Problem Statement:Write a program to compute the sum of elements in a generic list.

n
The program should accept numeric values of Integer, Double, or Float type using
wrapper classes and generics. su
tia
lgo

Description:
ga
3@

Create a generic class GenericSum<T extends Number>.


00

Implement a method sum(List<T> list) to compute the sum of elements.


801

Ensure type safety by restricting generics to numeric wrapper classes.


e1
cs

Input Format:
4s
h.2

First line: number of elements n


es

Second line: n space-separated numbers


m
so

Output Format:
h(
es

Sum of all elements


m
So

Sample Input:
510 20 30 40 50

Sample Output:
Sum: 150.0

Completion Status: Completed

Concepts Included:
GU 28 3rd Sem Java Prog. Pre-Midterm

Language Used: JAVA 8

Source Code:
import [Link].*;
class GenericSum<T extends Number> {
public double sum(List<T> list) {
double total = 0;
for (T num : list) {
total += [Link]();
}
return total;
}

)
.in
}

ac
public class Main {

ty.
public static void main(String[] args) {

rsi
Scanner sc = new Scanner([Link]);

ive
int n = [Link]();

n
List<Double> list = new ArrayList<>();
for (int i = 0; i < n; i++) { su
tia
[Link]([Link]());
lgo

}
ga

GenericSum<Double> calculator = new GenericSum<>();


3@

[Link]("Sum: " + [Link](list));


00

[Link]();
80

}
1
e1

}
cs
4s

Compilation Details:
h.2
es
m

TestCase1:
so
h(

Input:
es
m

< hidden >


So

Expected Output:
< hidden >

Output:
Sum: 15.0

Compilation Status: Passed


Execution Time:
0.135s

TestCase2:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Sum: 101.0

Compilation Status: Passed


Execution Time:
0.126s

)
.in
ac
TestCase3:

ty.
rsi
Input:

n ive
< hidden >
su
tia
Expected Output:
lgo
ga

< hidden >


3@

Output:
00
80

Sum: 600.0
1
e1

Compilation Status: Passed


cs
4s

Execution Time:
h.2
es

0.12s
m
so
h(

TestCase4:
es
m

Input:
So

< hidden >

Expected Output:
< hidden >

Output:
Sum: 23.1

Compilation Status: Passed


Execution Time:
0.128s
34. Median Finder
Problem Statement:Write a program to find the median of a list of numeric values
using wrapper classes and generics. The program must sort the list and find the
middle value (or average of two middle values if the list size is even).

Description:

Create a generic class MedianFinder<T extends Number & Comparable<T>>.

Implement a method findMedian(List<T> list) to return the median.

Use [Link]() for type-safe sorting.

Input Format:

First line: number of elements n

)
.in
Second line: n space-separated numbers

ac
ty.
Output Format:

rsi
Median value

n ive
Sample Input: su
tia
lgo

510 20 30 40 50
ga
3@

Sample Output:
00
80

Median: 30.0
1
e1
cs
4s

Completion Status: Completed


h.2
es

Concepts Included:
m
so
h(

GU 28 3rd Sem Java Prog. Pre-Midterm


es
m

Language Used: JAVA 8


So

Source Code:
import [Link].*;
class MedianFinder<T extends Number & Comparable<T>> {
public double findMedian(List<T> list) {
if (list == null || [Link]()) {
return 0;
}

[Link](list); // Sort the list


int n = [Link]();
if (n % 2 == 1) {
// Odd size, return middle element
return [Link](n / 2).doubleValue();
} else {
// Even size, average two middle elements
double mid1 = [Link](n / 2 - 1).doubleValue();
double mid2 = [Link](n / 2).doubleValue();
return (mid1 + mid2) / 2.0;
}
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
List<Double> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
[Link]([Link]());

)
.in
}

ac
MedianFinder<Double> finder = new MedianFinder<>();

ty.
[Link]("Median: " + [Link](list));

rsi
[Link]();

ive
}

n
}
su
tia
lgo

Compilation Details:
ga
3@

TestCase1:
00
80

Input:
1
e1

< hidden >


cs
4s

Expected Output:
h.2
es

< hidden >


m
so

Output:
h(
es

Median: 17.5
m
So

Compilation Status: Passed


Execution Time:
0.12s

TestCase2:
Input:
< hidden >

Expected Output:
< hidden >
Output:
Median: 6.0

Compilation Status: Passed


Execution Time:
0.121s

TestCase3:
Input:
< hidden >

Expected Output:

)
.in
ac
< hidden >

ty.
rsi
Output:

n ive
Median: 100.0
su
tia
Compilation Status: Passed
lgo
ga

Execution Time:
3@

0.127s
00
801

TestCase4:
e1
cs

Input:
4s
h.2

< hidden >


es
m

Expected Output:
so
h(

< hidden >


es
m

Output:
So

Median: 4.0

Compilation Status: Passed


Execution Time:
0.131s

35. Sum of Squares


Problem Statement:Write a program to calculate the sum of squares of a list of
numeric values using wrapper classes and generics.

Description:
Create a generic class SumOfSquares<T extends Number>.

Implement computeSumOfSquares(List<T> list) to return the sum of squares.

Use .doubleValue() for numeric conversion.

Input Format:

First line: number of elements n

Second line: n space-separated numbers

Output Format:

Sum of squares

Sample Input:

)
.in
32 3 4

ac
ty.
rsi
Sample Output:

n ive
Sum of Squares: 29.0
su
tia
lgo

Completion Status: Completed


ga
3@

Concepts Included:
00
80

GU 28 3rd Sem Java Prog. Pre-Midterm


1
e1
cs

Language Used: JAVA 8


4s
h.2
es

Source Code:
m
so

import [Link].*;
h(

class SumOfSquares<T extends Number> {


es

public double computeSumOfSquares(List<T> list) {


m

double sum = 0.0;


So

for (T num : list) {


double val = [Link]();
sum += val * val;
}
return sum;
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]([Link]().trim()); // number of elements
String[] tokens = [Link]().trim().split("\\s+"); // read n numbers as strings
List<Double> numbers = new ArrayList<>();
for (int i = 0; i < n; i++) {
[Link]([Link](tokens[i]));
}
SumOfSquares<Double> obj = new SumOfSquares<>();
double result = [Link](numbers);
[Link]("Sum of Squares: " + result);
[Link]();
}
}

Compilation Details:

TestCase1:
Input:
< hidden >

)
.in
Expected Output:

ac
ty.
< hidden >

rsi
ive
Output:

n
Sum of Squares: 55.0 su
tia
lgo

Compilation Status: Passed


ga
3@

Execution Time:
00
80

0.12s
1
e1
cs

TestCase2:
4s
h.2

Input:
es

< hidden >


m
so

Expected Output:
h(
es

< hidden >


m
So

Output:
Sum of Squares: 3000.0

Compilation Status: Passed


Execution Time:
0.128s

TestCase3:
Input:
< hidden >
Expected Output:
< hidden >

Output:
Sum of Squares: 50.5

Compilation Status: Passed


Execution Time:
0.11s

TestCase4:
Input:

)
.in
ac
< hidden >

ty.
rsi
Expected Output:

n ive
< hidden >
su
tia
Output:
lgo
ga

Sum of Squares: 49.0


3@

Compilation Status: Passed


00
80

Execution Time:
1
e1

0.106s
cs
4s
h.2
es

36. Max-Min Difference Calculator


m
so

Problem Statement:Write a program that computes the difference between the


h(

maximum and minimum values of a numeric list using wrapper classes and generics.
es
m

Description:
So

Create a generic class MaxMinDifference<T extends Number & Comparable<T>>.

Implement findDifference(List<T> list) to return (max - min).

Ensure type-safety using generics.

Input Format:

First line: number of elements n

Second line: n space-separated numbers

Output Format:

Difference between max and min


Sample Input:
510 20 30 5 15

Sample Output:
Difference: 25.0

Completion Status: Completed

Concepts Included:
GU 28 3rd Sem Java Prog. Pre-Midterm

)
.in
Language Used: JAVA 8

ac
ty.
rsi
Source Code:

n ive
import [Link].*;
su
class MaxMinDifference<T extends Number & Comparable<T>> {
tia
public double findDifference(List<T> list) {
lgo

if (list == null || [Link]()) {


ga

return 0;
3@

}
00

T max = [Link](0);
80

T min = [Link](0);
1

for (T num : list) {


e1

if ([Link](max) > 0) {
cs

max = num;
4s
h.2

}
if ([Link](min) < 0) {
es

min = num;
m
so

}
h(

}
es

return [Link]() - [Link]();


m

}
So

}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int n = [Link]();
List<Double> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
[Link]([Link]());
}
MaxMinDifference<Double> calculator = new MaxMinDifference<>();
double difference = [Link](list);
[Link]("Difference: " + difference);
[Link]();
}
}
Compilation Details:

TestCase1:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Difference: 75.0

Compilation Status: Passed

)
.in
ac
Execution Time:

ty.
rsi
0.123s

n ive
TestCase2: su
tia
lgo

Input:
ga
3@

< hidden >


00

Expected Output:
801

< hidden >


e1
cs

Output:
4s
h.2

Difference: 3.5
es
m

Compilation Status: Passed


so
h(

Execution Time:
es
m

0.127s
So

TestCase3:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Difference: 15.0

Compilation Status: Passed


Execution Time:
0.124s

TestCase4:
Input:
< hidden >

Expected Output:
< hidden >

Output:
Difference: 60.0

)
.in
ac
Compilation Status: Passed

ty.
rsi
Execution Time:

n ive
0.123s
su
tia
lgo
ga
3@
00
801
e1
cs
4s
h.2
es
m
so
h(
es
m
So

You might also like