Lab 2 Hamza Nazir
Advanced Object-Oriented Programming
LAB REPORT: 3
Submitted By:
Hamza Nazir
(2872)
Submitted To:
Ma’am Syeda Humaira Batool
DATE:10/05/2023
Bscs-40B (4rd Semester) Evening
Task 1:
Lab 2 Hamza Nazir 1
Objective
1. Create a Class with instance attributes
Write a python program to create a Vehicle class with max_speed and mileage instance
attributes.
2. Create a Vehicle class without any variables and methods
3. Create a child class Bus that will inherit all of the
variables and methods of the Vehicle class
4. Class Inheritance
Given:
Create a Bus class that inherits from the Vehicle class. Give the capacity argument
of Bus.seating_capacity() a default value of 50.
5. Define a property that must have the same value for every
class instance (object)
Define a class attribute”color” with a default value white. I.e., Every Vehicle should be
white.
6. Class Inheritance
Given:
Create a Bus child class that inherits from the Vehicle class. The default fare charge of
any vehicle is seating capacity * 100. If Vehicle is Bus instance, we need to add an extra
10% on full fare as a maintenance charge. So total fare for bus instance will become
the final amount = total fare + 10% of the total fare.
Note: The bus seating capacity is 50. so the final fare amount should be 5500. You need
to override the fare() method of a Vehicle class in Bus class
Code:
class vechile
public class vechile {
int max_speed ;
int mileage;
int seating;
void set_seating_anyVechicle(int seating)
{
Lab 2 Hamza Nazir 2
this.seating=seating;
}
void fare()
{
System.out.println("Any vechicle fare charges :"+seating*100);
}
class Bus
public class Bus extends vechile{
void Busseating_capacity()
{
seating=50;
}
void fare()
{
int a=((seating*100)/50)*100;
System.out.println("bus fare charges "+(a+(seating*100)));
}
Pet interface
public interface pet {
void setName(String name);
String getNmae();
void play();
Test class / Main class
public class Main {
public static void main(String[] args) {
Bus bus_obj=new Bus();
Lab 2 Hamza Nazir 3
bus_obj.Busseating_capacity();
bus_obj.fare();
vechile obj=new vechile();
obj.set_seating_anyVechicle(50);
obj.fare();
}
}
Output
Task 2:
Objective
Q1: Write a Python class Employee with attributes like emp_id, emp_name,
emp_salary, and emp_department and methods like calculate_emp_salary,
emp_assign_department, and print_employee_details.
Sample Employee Data:
"ADAMS", "E7876", 50000, "ACCOUNTING"
"JONES", "E7499", 45000, "RESEARCH"
"MARTIN", "E7900", 50000, "SALES"
"SMITH", "E7698", 55000, "OPERATIONS"
Use 'assign_department' method to change the department of an employee.
Use 'print_employee_details' method to print the details of an employee.
Use 'calculate_emp_salary' method takes two arguments: salary and
hours_worked, which is the number of hours worked by the employee. If the
Lab 2 Hamza Nazir 4
number of hours worked is more than 50, the method computes overtime and
adds it to the salary. Overtime is calculated as following formula:
overtime = hours_worked – 50
Overtime amount = (overtime * (salary / 50))
Code:
class Employee
public class Employee {
String emp_id;
String emp_name;
int emp_salary;
String emp_department;
public Employee(String emp_id, String emp_name, int emp_salary, String emp_department) {
this.emp_id = emp_id;
this.emp_name = emp_name;
this.emp_salary = emp_salary;
this.emp_department = emp_department;
}
public void change_Emp_department(String emp_department) {
this.emp_department = emp_department;
}
int calculate_emp_salary(int salary, int hours_worked)
{
if (salary>50){
int overtime = hours_worked- 50;
int Overtime_amount = (overtime * (salary / 50));
return Overtime_amount;
}
else{
return salary;
}
}
void print_employee_details()
{
// "ADAMS", "E7876", 50000, "ACCOUNTING"
System.out.println("'"+emp_name+"'"+" "+emp_id+" "+"'"+emp_salary+"'"+" "+emp_department+"'");
}
}
Test class / Main class
public class Main1 {
public static void main(String[] args) {
Lab 2 Hamza Nazir 5
Employee e1=new Employee("dhddh79","hamza",5000,"gazali");
Employee e2=new Employee("drfes4hh","hsubhan",5000,"gazali");
Employee e3=new Employee("dhh74e9","zeshan",5000,"gazali");
Employee e4=new Employee("dhhee79","akkhter",5000,"gazali");
Employee e5=new Employee("dhffh79","lava",5000,"gazali");
Employee e6=new Employee("dhbhbh79","oho",5000,"gazali");
Employee e7=new Employee("dhvcgh79","ruto",5000,"gazali");
e1.print_employee_details();
}
Output
Task 3:
Objective
Q2: Write a Python class BankAccount with attributes like account_number,
balance, date_of_opening and customer_name, and methods like deposit,
withdraw,
Code:
class BankAccount
public class BankAccount {
String account_number;
Lab 2 Hamza Nazir 6
float balance;
String date_of_opening;
String customer_name;
public BankAccount(String account_number, float balance, String date_of_opening, String customer_name) {
this.account_number = account_number;
this.balance = balance;
this.date_of_opening = date_of_opening;
this.customer_name = customer_name;
}
void deposit(float amount)
{
balance=balance+amount;
System.out.println("you are deposit "+amount+" Now current ballence is :"+balance);
}
void withdraw(float a)
{
balance=balance-a;
System.out.println("your are withdrawing ammount "+a+" now available ballence is "+balance);
}
void check_balance()
{
System.out.println("avalable ballance :"+balance);
}
}
Test class / Main class
public class main1 {
public static void main(String[] args) {
BankAccount hamza=new BankAccount("32323g3",23231,"12:32 am","hamza");
hamza.check_balance();
hamza.deposit(2457);
hamza.withdraw(756.87f);
}
Output
Lab 2 Hamza Nazir 7
Lab 2 Hamza Nazir 8