0% found this document useful (0 votes)
10 views

ooplab08

The document is a lab manual for Object Oriented Programming (OOP) tasks, featuring three programs that demonstrate the use of abstract classes and inheritance. Program 1 showcases a vehicle hierarchy with classes for Car, Bike, and Truck, while Program 2 illustrates a payment system with CreditCard and PayPal payment classes. Program 3 presents an employee management system with Manager, Developer, and Intern classes, each implementing their specific work behavior.

Uploaded by

mjoy14129
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)
10 views

ooplab08

The document is a lab manual for Object Oriented Programming (OOP) tasks, featuring three programs that demonstrate the use of abstract classes and inheritance. Program 1 showcases a vehicle hierarchy with classes for Car, Bike, and Truck, while Program 2 illustrates a payment system with CreditCard and PayPal payment classes. Program 3 presents an employee management system with Manager, Developer, and Intern classes, each implementing their specific work behavior.

Uploaded by

mjoy14129
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
You are on page 1/ 7

Object Oriented Programming (OOP)

Lab Manual
Lab Task 8
Name: Abdul Samad
Roll Number: 39337

1
Program no. 01
Code:
abstract class Vehicle {
String brand;
int speed;
Vehicle(String brand, int speed) {
this.brand = brand;
this.speed = speed;
}
abstract void start();
abstract void stop();
}
class Car extends Vehicle {
Car(String brand, int speed) {
super(brand, speed);
}
@Override
void start() {
System.out.println("Car " + brand + " starts at speed " + speed + " km/h.");
}
@Override
void stop() {
System.out.println("Car " + brand + " stops.");
}
}
class Bike extends Vehicle {
Bike(String brand, int speed) {

2
super(brand, speed);
}
@Override
void start() {
System.out.println("Bike " + brand + " starts at speed " + speed + " km/h.");
}
@Override
void stop() {
System.out.println("Bike " + brand + " stops.");
}
}
class Truck extends Vehicle {
Truck(String brand, int speed) {
super(brand, speed);
}
@Override
void start() {
System.out.println("Truck " + brand + " starts at speed " + speed + " km/h.");
}
@Override
void stop() {
System.out.println("Truck " + brand + " stops.");
}
}
public class VehicleDemo {
public static void main(String[] args) {
Vehicle car = new Car("Toyota", 120);

3
Vehicle bike = new Bike("Yamaha", 80);
Vehicle truck = new Truck("Volvo", 60);
car.start();
car.stop();
bike.start();
bike.stop();
truck.start();
truck.stop();
}
}
Program no.02
Code:
abstract class Payment {
double amount;
Payment(double amount) {
this.amount = amount;
}
abstract void processPayment();
}
class CreditCardPayment extends Payment {
CreditCardPayment(double amount) {
super(amount);
}
@Override
void processPayment() {
System.out.println("Processing credit card payment of $" + amount);
}

4
}
class PayPalPayment extends Payment {
PayPalPayment(double amount) {
super(amount);
}
@Override
void processPayment() {
System.out.println("Processing PayPal payment of $" + amount);
}
}
public class PaymentSystemDemo {
public static void main(String[] args) {
Payment creditCardPayment = new CreditCardPayment(150.75);
Payment payPalPayment = new PayPalPayment(200.50);

creditCardPayment.processPayment();
payPalPayment.processPayment();
}
}
Program no.03
Code:
abstract class Employee {
String name;
int id;
Employee(String name, int id) {
this.name = name;
this.id = id;

5
}
abstract void work();
}
class Manager extends Employee {
Manager(String name, int id) {
super(name, id);
}
@Override
void work() {
System.out.println("Manager " + name + " (ID: " + id + ") oversees projects.");
}
}
class Developer extends Employee {
Developer(String name, int id) {
super(name, id);
}
@Override
void work() {
System.out.println("Developer " + name + " (ID: " + id + ") writes code.");
}
}
class Intern extends Employee {
Intern(String name, int id) {
super(name, id);
}
@Override
void work() {

6
System.out.println("Intern " + name + " (ID: " + id + ") assists in tasks.");
}
}
public class EmployeeManagementDemo {
public static void main(String[] args) {
Employee manager = new Manager("Alice", 101);
Employee developer = new Developer("Bob", 102);
Employee intern = new Intern("Charlie", 103);

manager.work();
developer.work();
intern.work();
}
}

You might also like