Assignment - 3: Object Oriented Programming (PCC-CS503)
Write Java programs to solve the following problems-
1. Create a class Calculator
Use method overloading to implement a method calculate() with the following
variations:
calculate(int a, int b) – returns sum of two integers
calculate(double a, double b) – returns product of two double values
calculate(String s1, String s2) – returns concatenation of two strings
calculate(int[] arr) – returns the sum of elements in the integer array
2. Create a class Stack
Data Members: Integer array stack[], top
Constructor to initialize stack size, and top
Methods:
push() to insert elements
pop() to remove elements
display() to print the stack contents
3. Create a class Queue
Data Members: Integer array queue[], front, rear
Constructor to initialize queue size, front, rear
Methods:
enqueue() to add elements
dequeue() to remove elements
display() to print the queue elements
4. Create a super class Vehicle with
Data members: brand, model, and year.
Method displayVehicle() to show the details
Create two Sub-classes: Car and Bike
Car with additional fields: seatingCapacity, fuelType and a method displayCar()
Bike with additional fields: engineCapacity, isElectric and a method displayBike()
From main method accept details for one Car and one Bike from the user. Display their
complete details.
5. Create a super class Person with the following attributes and methods:
Attributes: name, age, gender
Methods: isAdult() – returns true if age ≥ 18
displayBasicInfo() – prints name, age, and gender
Create a derived class Employee with:
Attributes: employeeId, department, salary
Methods:
calculateBonus() – returns 10% of salary
displayEmployeeDetails() – uses displayBasicInfo() from Person and prints
all employee data