1.
In a network system, a server is considered perfectly balanced if the total resources it
shares with others (i.e., its divisors excluding itself) are exactly equal to the server's
capacity. Simulate this by writing a program that checks if a given number is a Perfect
Number-is a positive integer that is equal to the sum of its proper positive
divisors(6,28,496,8128). Also An educational app aims to help children learn
multiplication. When a number is input, the app displays its multiplication table up to 10
terms. Write a program that takes a number and prints its multiplication table.
import [Link];
public class PerfectNumberAndTable {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();
// Check Perfect Number
int sum = 0;
for (int i = 1; i < num; i++) {
if (num % i == 0)
sum += i;
if (sum == num)
[Link](num + " is a Perfect Number.");
else
[Link](num + " is not a Perfect Number.");
// Multiplication Table
[Link]("Multiplication Table of " + num + ":");
for (int i = 1; i <= 10; i++)
[Link](num + " x " + i + " = " + (num * i));
}
[Link] an electricity billing system, certain meter numbers are flagged as invalid if the total
reading is not divisible by the sum of its digits. Write a program that checks if a meter
number is a Harshad (Niven) Number(an integer that is divisible by the sum of its digit)to
detect such anomalies. Also, An educational app aims to help children learn
multiplication. When a number is input, the app displays its multiplication table up to 10
terms. Write a program that takes a number and prints its multiplication table.
import [Link];
public class HarshadNumber {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();
int temp = num, sum = 0;
while (temp > 0) {
sum += temp % 10;
temp /= 10;
if (num % sum == 0)
[Link](num + " is a Harshad (Niven) Number.");
else
[Link](num + " is not a Harshad Number.");
[Link]("Multiplication Table of " + num + ":");
for (int i = 1; i <= 10; i++)
[Link](num + " x " + i + " = " + (num * i));
}
[Link] modeling a car in Java class. A car has properties like brand, color, and
speed, and behaviors such as accelerating, braking, and honking.
class Car {
String brand, color;
int speed;
void accelerate() {
speed += 10;
[Link]("Accelerating... Speed: " + speed);
void brake() {
speed -= 10;
[Link]("Braking... Speed: " + speed);
void honk() {
[Link](brand + " says Beep Beep!");
public class CarDemo {
public static void main(String[] args) {
Car c = new Car();
[Link] = "Toyota";
[Link] = "Red";
[Link] = 50;
[Link]();
[Link]();
[Link]();
}
[Link] a program for String compression that compresses consecutive repeated
characters into a compact format. For example, "aaabbcccc" becomes "a3b2c4"—
commonly used in data compression, logging, or compact message formatting.
public class StringCompression {
public static void main(String[] args) {
String str = "aaabbcccc";
StringBuilder compressed = new StringBuilder();
int count = 1;
for (int i = 1; i <= [Link](); i++) {
if (i < [Link]() && [Link](i) == [Link](i - 1))
count++;
else {
[Link]([Link](i - 1)).append(count);
count = 1;
[Link]("Compressed String: " + compressed);
[Link] Student Attendance system where the teacher wants to maintain a list of
student names. The list should support adding, inserting, removing students, and
checking whether a student exists. The teacher also wants to know how many students
are in the class(Use vector method).
import [Link].*;
public class StudentAttendance {
public static void main(String[] args) {
Vector<String> students = new Vector<>();
[Link]("Ravi");
[Link]("Sneha");
[Link]("Amit");
[Link](1, "Kiran"); // insert at position
[Link]("Amit"); // remove
[Link]("List of students: " + students);
[Link]("Contains Sneha? " + [Link]("Sneha"));
[Link]("Total students: " + [Link]());
6.A car rental service records the mileage (in km) of its 5 cars after each day's use.
Develop a Java program to(use Array):Accept mileage readings for 5 [Link] each
car's mileage.
Find the car with the highest and lowest mileage. Calculate total and average
mileage. import [Link].*;
public class CarMileage {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int[] mileage = new int[5];
int total = 0;
for (int i = 0; i < 5; i++) {
[Link]("Enter mileage for car " + (i + 1) + ": ");
mileage[i] = [Link]();
total += mileage[i];
int max = mileage[0], min = mileage[0];
for (int m : mileage) {
if (m > max) max = m;
if (m < min) min = m;
[Link]("Highest Mileage: " + max);
[Link]("Lowest Mileage: " + min);
[Link]("Total Mileage: " + total);
[Link]("Average Mileage: " + total / 5.0);
7. Student Registration System
A university needs a system to register students. Sometimes a student is added with
complete details, sometimes with only partial details, and sometimes by copying details
from an existing student record. Design a Student class to handle all these cases when
creating new students.(Hint : Create a Student class with:Default constructor → sets
name as "Unknown" and age as 0. Parameterized constructor → accepts name and
[Link] constructor → creates a new student by copying details from another student.)
class Student {
String name;
int age;
Student() {
name = "Unknown";
age = 0;
}
Student(String n, int a) {
name = n;
age = a;
Student(Student s) {
[Link] = [Link];
[Link] = [Link];
void display() {
[Link]("Name: " + name + ", Age: " +
age); }
public class StudentDemo {
public static void main(String[] args) {
Student s1 = new Student();
Student s2 = new Student("Riya", 19);
Student s3 = new Student(s2);
[Link]();
[Link]();
[Link]();
}
8. Bank Account Creation
A bank offers different ways for customers to open an account: with no details (default
settings), with just account type, with account type and initial balance, and with account
type, balance, and account holder name. Design a BankAccount class that can handle
these different account creation scenarios.
(Hint: Create a BankAccount class demonstrating constructor overloading and
constructor chaining using this().
● Constructor 1: Default → zero balance, "Savings" type.
● Constructor 2: Accepts account type only.
● Constructor 3: Accepts account type and initial balance.
● Constructor 4: Accepts account type, initial balance, and account holder name (calls
previous constructor using this()).
class BankAccount {
String type, holder;
double balance;
BankAccount() {
this("Savings", 0, "Unknown");
BankAccount(String type) {
this(type, 0, "Unknown");
BankAccount(String type, double balance) {
this(type, balance, "Unknown");
BankAccount(String type, double balance, String holder) {
[Link] = type;
[Link] = balance;
[Link] = holder;
}
void display() {
[Link](holder + " | " + type + " | ₹" + balance);
public class BankDemo {
public static void main(String[] args) {
BankAccount a1 = new BankAccount();
BankAccount a2 = new BankAccount("Current");
BankAccount a3 = new BankAccount("Savings", 5000);
BankAccount a4 = new BankAccount("Fixed", 10000, "Amit");
[Link](); [Link](); [Link](); [Link]();
[Link] Inventory System
A vehicle showroom stores details of vehicles. Every vehicle has a brand and model.
Cars are a type of vehicle and also store information about fuel type. Design a class
structure that represents these relationships and allows creating objects with all required
details.
● (Hint: Create a base class Vehicle with a parameterized constructor to set brand and
model.
Create a subclass Car with its own parameterized constructor that calls the base
class constructor using super().
class Vehicle {
String brand, model;
Vehicle(String b, String m) {
brand = b; model = m;
}
}
class Car extends Vehicle {
String fuelType;
Car(String b, String m, String f) {
super(b, m);
fuelType = f;
void display() {
[Link](brand + " " + model + " | Fuel: " + fuelType);
public class VehicleDemo {
public static void main(String[] args) {
Car c = new Car("Honda", "City", "Petrol");
[Link]();
10. A hotel booking system needs a class HotelRoom to manage room details. ● If no
information is given, the room should be created with default type "Standard" and
price ₹2000.
● If only the room type is given, the price should be set based on the type (Standard →
₹2000, Deluxe → ₹3500, Suite → ₹5000).
● There should also be a way to create a new room by duplicating the details of an
existing room.
Write a program to create different types of rooms and display their details.
class HotelRoom {
String type;
double price;
HotelRoom() {
this("Standard");
HotelRoom(String type) {
[Link] = type;
switch (type) {
case "Deluxe": price = 3500; break;
case "Suite": price = 5000; break;
default: price = 2000;
HotelRoom(HotelRoom r) {
[Link] = [Link];
[Link] = [Link];
void display() {
[Link](type + " Room | ₹" +
price); }
public class HotelDemo {
public static void main(String[] args) {
HotelRoom r1 = new HotelRoom();
HotelRoom r2 = new HotelRoom("Suite");
HotelRoom r3 = new HotelRoom(r2);
[Link](); [Link](); [Link]();
11. Design Electronic Device system by Creating an interface Device with methods turnOn()
and turnOff(). Implement it for Light and Fan. Also create another interface SmartFeature for
voice control.
interface Device {
void turnOn();
void turnOff();
interface SmartFeature {
void voiceControl();
class Light implements Device, SmartFeature {
public void turnOn() { [Link]("Light turned ON"); }
public void turnOff() { [Link]("Light turned OFF"); }
public void voiceControl() { [Link]("Light responding to voice command"); }
class Fan implements Device, SmartFeature {
public void turnOn() { [Link]("Fan turned ON"); }
public void turnOff() { [Link]("Fan turned OFF"); }
public void voiceControl() { [Link]("Fan responding to voice command");
}}
public class DeviceDemo {
public static void main(String[] args) {
Light l = new Light();
Fan f = new Fan();
[Link](); [Link]();
[Link](); [Link]();
12. Design Car rental [Link] an abstract Vehicle class for a rental service. Different
types of vehicles (Car, Bike) should inherit from it and calculate rental cost differently.(Hint:
Use: Abstract class)
abstract class Vehicle {
String type;
Vehicle(String t) { type = t; }
abstract double calculateRent(int days);
class Car extends Vehicle {
Car() { super("Car"); }
double calculateRent(int days) { return days * 1000; }
class Bike extends Vehicle {
Bike() { super("Bike"); }
double calculateRent(int days) { return days * 500; }
public class RentalDemo {
public static void main(String[] args) {
Vehicle v1 = new Car();
Vehicle v2 = new Bike();
[Link]("Car Rent (3 days): ₹" + [Link](3));
[Link]("Bike Rent (4 days): ₹" + [Link](4));
13.A smartphone should be able to make calls, play music, and take photos. Making calls is
a basic phone feature, but music and camera are extra features.
Hint: Use a Phone class for calls, and create MusicPlayer and Camera interfaces. A
SmartPhone should extend Phone and implement both interfaces.
interface MusicPlayer {
void playMusic();
interface Camera {
void takePhoto();
class Phone {
void makeCall(String number) {
[Link]("Calling " + number + "...");
class SmartPhone extends Phone implements MusicPlayer, Camera {
public void playMusic() { [Link]("Playing music..."); }
public void takePhoto() { [Link]("Taking photo..."); }
void videoCall(String number) {
[Link]("Video calling " + number + "...");
}
public class SmartPhoneDemo {
public static void main(String[] args) {
SmartPhone sp = new SmartPhone();
[Link]("9876543210");
[Link]();
[Link]();
[Link]("9876543210");
14. A company needs a payroll system. Every employee has a name and salary, but salary
calculation differs. A FullTimeEmployee gets a fixed monthly salary, while a
PartTimeEmployee is paid based on the number of hours worked. The program should
calculate and display the salary depending on the employee type.
Hint: Create an abstract class Employee with abstract method calculatePay(). Extend it into
FullTimeEmployee and PartTimeEmployee with different implementations.
abstract class Employee {
String name;
Employee(String n) { name = n; }
abstract double calculatePay();
class FullTimeEmployee extends Employee {
double salary;
FullTimeEmployee(String n, double s) { super(n); salary = s; }
double calculatePay() { return salary; }
}
class PartTimeEmployee extends Employee {
int hours;
double rate;
PartTimeEmployee(String n, int h, double r) { super(n); hours = h; rate = r; }
double calculatePay() { return hours * rate; }
public class PayrollDemo {
public static void main(String[] args) {
Employee e1 = new FullTimeEmployee("Ravi", 25000);
Employee e2 = new PartTimeEmployee("Kiran", 40, 200);
[Link]([Link] + " earns ₹" +
[Link]()); [Link]([Link] + " earns ₹" +
[Link]()); }
15. Write a program where Multiple inheritance is implemented in java.
interface A { void showA(); }
interface B { void showB(); }
class C implements A, B {
public void showA() { [Link]("Feature from A");
} public void showB() { [Link]("Feature from B"); }
public class MultipleInheritanceDemo {
public static void main(String[] args) {
C obj = new C();
[Link]();
[Link]();
16. Design a Area of Shape Calculator.
1. Create a Shape class with overloaded methods area():
o area(int side) → area of square.
o area(int length, int breadth) → area of rectangle.
o area(double radius) → area of circle.
class Shape {
void area(int side) {
[Link]("Area of Square: " + (side * side));
void area(int length, int breadth) {
[Link]("Area of Rectangle: " + (length *
breadth)); }
void area(double radius) {
[Link]("Area of Circle: " + (3.14 * radius *
radius)); }
public class ShapeDemo {
public static void main(String[] args) {
Shape s = new Shape();
[Link](5);
[Link](4, 6);
[Link](3.5);
}
[Link] a Smartphone Feature:
2. Phone class has overloaded methods call():
o call(Stringnumber), call(String number, int duration)
2. Smartphone extends Phone and overrides call() to include video call
functionality.
class Phone {
void call(String number) {
[Link]("Calling " + number);
void call(String number, int duration) {
[Link]("Calling " + number + " for " + duration + " mins");
class SmartPhone extends Phone {
@Override
void call(String number) {
[Link]("Video calling " + number);
public class PhoneDemo {
public static void main(String[] args) {
Phone p = new Phone();
SmartPhone s = new SmartPhone();
[Link]("9999999999");
[Link]("9999999999", 5);
[Link]("8888888888");
18. Design Employee Salary Calculation portal:
Design a program to manage employees in a company.
1. Create an Employee class with a method calculateSalary().
o Demonstrate method overloading by:
▪ calculateSalary(double basic)
▪ calculateSalary(double basic, double bonus)
2. Create a subclass Manager that overrides calculateSalary() to add an extra allowance
class Employee {
void calculateSalary(double basic) {
[Link]("Salary: ₹" + basic);
void calculateSalary(double basic, double bonus) {
[Link]("Salary with Bonus: ₹" + (basic + bonus));
class Manager extends Employee {
@Override
void calculateSalary(double basic) {
double allowance = 0.2 * basic;
[Link]("Manager Salary with Allowance: ₹" + (basic + allowance));
}
public class SalaryDemo {
public static void main(String[] args) {
Employee e = new Employee();
Manager m = new Manager();
[Link](30000);
[Link](30000, 5000);
[Link](40000);
19. Design University result program. Create a package university that contains:A class
Student with fields: rollNo, name, and marks[]. A method calculateAverage() to compute the
average marks.A method displayResult() to print pass/fail status (pass if average ≥ 28).
Write a separate program outside the package to import the class and evaluate multiple
students.
package university;
public class Student {
int rollNo;
String name;
int marks[];
public Student(int rollNo, String name, int[] marks) {
[Link] = rollNo;
[Link] = name;
[Link] = marks;
}
public double calculateAverage() {
int sum = 0;
for (int m : marks)
sum += m;
return sum / (double) [Link];
public void displayResult() {
double avg = calculateAverage();
[Link](name + " (" + rollNo + ") Avg: " + avg);
if (avg >= 28)
[Link]("Result: PASS");
else
[Link]("Result: FAIL");
import [Link];
public class Main {
public static void main(String[] args) {
int[] marks = {30, 25, 35};
Student s1 = new Student(101, "Ravi", marks);
[Link]();
[Link] Library Book management program. Create a package library containing a class
Book with fields like bookId, title, author, and [Link] methods issueBook(),
returnBook(), and displayDetails().In another program outside the package, create multiple
books and simulate issuing and returning.
package library;
public class Book {
int bookId;
String title, author;
boolean isAvailable;
public Book(int id, String t, String a) {
bookId = id; title = t; author = a; isAvailable = true;
public void issueBook() {
if (isAvailable) {
isAvailable = false;
[Link](title + " issued.");
} else {
[Link](title + " is not available.");
public void returnBook() {
isAvailable = true;
[Link](title + " returned.");
public void displayDetails() {
[Link](bookId + " | " + title + " | " + author + " | Available: " +
isAvailable); }
}
import [Link];
public class LibraryMain {
public static void main(String[] args) {
Book b1 = new Book(1, "Java Basics", "James Gosling");
[Link]();
[Link]();
[Link]();
[Link] wants to develop a simple calculator program that performs division of two
numbers. If the user enters 0 as denominator, it should throw an ArithmeticException and
display a proper error message. The program should also handle any invalid input entered
by the user (e.g., entering a string instead of a number) using
[Link] of an exception, the program should display a message
that the calculation attempt has finished.
import [Link].*;
public class Calculator {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
try {
[Link]("Enter numerator: ");
int num = [Link]();
[Link]("Enter denominator: ");
int den = [Link]();
int result = num / den;
[Link]("Result: " + result);
} catch (ArithmeticException e) {
[Link]("Error: Division by zero not allowed.");
} catch (InputMismatchException e) {
[Link]("Error: Invalid input. Enter integers only.");
} finally {
[Link]("Calculation attempt finished.");
}
[Link] a Java Program to calculate the Result. Result should consist of name, seatno,
date, centre number and marks of sem-2 examination. Create a user defined exception class
MarksOutOfBoundsException, If Entered marks of any subject is greater than 100 or less
than 0, and then program should create a user defined Exception of type
MarksOutOfBoundsException and must have a provision to handle it.
import [Link].*;
class MarksOutOfBoundsException extends Exception {
MarksOutOfBoundsException(String msg) {
super(msg);
public class StudentResult {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
try {
[Link]("Enter marks (0–100): ");
int marks = [Link]();
if (marks < 0 || marks > 100)
throw new MarksOutOfBoundsException("Invalid marks entered!");
[Link]("Marks entered: " + marks);
} catch (MarksOutOfBoundsException e) {
[Link]("Exception: " + [Link]());
}
}
23. Design a Bank Application, bank has a rule that every account must maintain a
minimum balance of ₹[Link] a withdrawal makes the balance go below ₹1000, the program
should throw a custom exception [Link] program should handle
this exception and display a proper error message. Otherwise, it should display the new
balance.
import [Link].*;
class MinimumBalanceException extends Exception {
MinimumBalanceException(String msg) { super(msg); }
class BankAccount {
double balance = 2000;
void withdraw(double amount) throws MinimumBalanceException {
if (balance - amount < 1000)
throw new MinimumBalanceException("Withdrawal denied! Minimum balance ₹1000
required.");
balance -= amount;
[Link]("Withdrawal successful. New balance: ₹" +
balance); }
public class BankExceptionDemo {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
BankAccount b = new BankAccount();
try {
[Link]("Enter amount to withdraw: ");
double amt = [Link]();
[Link](amt);
} catch (MinimumBalanceException e) {
[Link]([Link]());
}
[Link] a Java program where three threads run concurrently: one fetches
temperature,another fetches humidity, and the third displays the combined weather
report. (Use
Runnable Interface).
File name: [Link]
class WeatherData {
int temperature;
int humidity;
boolean dataReady = false;
class TemperatureFetcher implements Runnable {
WeatherData data;
TemperatureFetcher(WeatherData data) {
[Link] = data;
public void run() {
try {
[Link]("Fetching temperature...");
[Link](1000);
[Link] = 30;
[Link]("Temperature fetched: " + [Link] +
"°C");
} catch (InterruptedException e) {
[Link]();
class HumidityFetcher implements Runnable {
WeatherData data;
HumidityFetcher(WeatherData data) {
[Link] = data;
public void run() {
try {
[Link]("Fetching humidity...");
[Link](1500);
[Link] = 65;
[Link]("Humidity fetched: " + [Link] + "%");
} catch (InterruptedException e) {
[Link]();
class WeatherDisplay implements Runnable {
WeatherData data;
WeatherDisplay(WeatherData data) {
[Link] = data;
public void run() {
try {
[Link](2000);
[Link]("\n------ Weather Report ------");
[Link]("Temperature: " + [Link] + "°C");
[Link]("Humidity: " + [Link] + "%");
[Link]("----------------------------");
} catch (InterruptedException e) {
[Link]();
public class WeatherReport {
public static void main(String[] args) {
WeatherData data = new WeatherData();
Thread t1 = new Thread(new TemperatureFetcher(data));
Thread t2 = new Thread(new HumidityFetcher(data));
Thread t3 = new Thread(new WeatherDisplay(data));
[Link]();
[Link]();
[Link]();
}
25 .Write a program in java using BufferedInputStream, BufferedOutputStream
class to
read/write the file (File should display your name, class and roll no)
import [Link].*;
public class FileReadWrite {
public static void main(String[] args) {
String fileName = "student_info.txt";
String content = "Name: Ansari Mohd Raza Farooque\nClass: TE
IT\nRoll No: 56";
try {
BufferedOutputStream bos = new BufferedOutputStream(new
FileOutputStream(fileName));
[Link]([Link]());
[Link]();
[Link]("Data written to file successfully.");
BufferedInputStream bis = new BufferedInputStream(new
FileInputStream(fileName));
int ch;
[Link]("\nReading data from file:");
while ((ch = [Link]()) != -1) {
[Link]((char) ch);
[Link]();
} catch (IOException e) {
[Link]();
}
}
[Link] a Java program using Swing to create an Online Shopping Page. The
GUI should
present a [JList] of available items (Laptop, Phone, Bag, Watch), along
with a [JTextArea] to
display the Selected Items. It must also contain two [JButtons] labeled Add
to Cart and
Checkout to complete the interface design.
File name: [Link]
import [Link].*;
import [Link].*;
import [Link].*;
public class OnlineShopping extends JFrame implements ActionListener {
JList<String> itemList;
JTextArea cartArea;
JButton addButton, checkoutButton;
public OnlineShopping() {
setTitle("Online Shopping Page");
setSize(400, 350);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new BorderLayout());
String[] items = {"Laptop", "Phone", "Bag", "Watch"};
itemList = new JList<>(items);
[Link](ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
JScrollPane listScroll = new JScrollPane(itemList);
[Link]([Link]("Available
Items"));
cartArea = new JTextArea();
[Link](false);
JScrollPane cartScroll = new JScrollPane(cartArea);
[Link]([Link]("Selected
Items"));
addButton = new JButton("Add to Cart");
checkoutButton = new JButton("Checkout");
[Link](this);
[Link](this);
JPanel buttonPanel = new JPanel();
[Link](addButton);
[Link](checkoutButton);
add(listScroll, [Link]);
add(cartScroll, [Link]);
add(buttonPanel, [Link]);
setVisible(true);
public void actionPerformed(ActionEvent e) {
if ([Link]() == addButton) {
[Link]<String> selected =
[Link]();
for (String item : selected) {
[Link](item + "\n");
}
} else if ([Link]() == checkoutButton) {
[Link](this, "Checkout
successful!\nThank you for shopping!");
[Link]("");
public static void main(String[] args) {
new OnlineShopping();
[Link] a Java application using AWT that functions as a Simple
Calculator. The GUI
should contain two TextFields for entering numbers, along with four Buttons
labeled Add,
Subtract, Multiply, and Divide. When any of these buttons is clicked, the
program should
compute the result and display it in a Label below the buttons.
import [Link].*;
import [Link].*;
public class SimpleCalculator extends Frame implements ActionListener {
TextField num1Field, num2Field;
Label resultLabel;
Button addBtn, subBtn, mulBtn, divBtn;
public SimpleCalculator() {
setTitle("Simple Calculator");
setSize(350, 250);
setLayout(new GridLayout(5, 2, 10, 10));
Label num1Label = new Label("Enter First Number:");
Label num2Label = new Label("Enter Second Number:");
resultLabel = new Label("Result: ");
num1Field = new TextField();
num2Field = new TextField();
addBtn = new Button("Add");
subBtn = new Button("Subtract");
mulBtn = new Button("Multiply");
divBtn = new Button("Divide");
add(num1Label);
add(num1Field);
add(num2Label);
add(num2Field);
add(addBtn);
add(subBtn);
add(mulBtn);
add(divBtn);
add(resultLabel);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
setVisible(true);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
});
public void actionPerformed(ActionEvent e) {
try {
double num1 = [Link]([Link]());
double num2 = [Link]([Link]());
double result = 0;
if ([Link]() == addBtn)
result = num1 + num2;
else if ([Link]() == subBtn)
result = num1 - num2;
else if ([Link]() == mulBtn)
result = num1 * num2;
else if ([Link]() == divBtn)
result = num2 != 0 ? num1 / num2 : [Link];
[Link]("Result: " + result);
} catch (NumberFormatException ex) {
[Link]("Invalid input! Please enter numbers.");
}
}
public static void main(String[] args) {
new SimpleCalculator();