0% found this document useful (0 votes)
51 views17 pages

Oop Assi Empoyee

The third document creates movie classes as the base class and subclasses for action, comedy and drama movies, creates arrays of movies, calls calculateFees methods, and compares movie titles to demonstrate polymorphism.

Uploaded by

Jawad Nasir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views17 pages

Oop Assi Empoyee

The third document creates movie classes as the base class and subclasses for action, comedy and drama movies, creates arrays of movies, calls calculateFees methods, and compares movie titles to demonstrate polymorphism.

Uploaded by

Jawad Nasir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

ASSIGNMENT

Object Oriented Programming

Submitted By: Syed Ahmad Hussain

SP18-BSE-108
Runner:

package lab7polymorphism;

/**

* @author Lenovo

*/

public class Lab7polymorphism {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

Employee[] employees = new Employee[4];

employees[0] = new basepluscomissionemploee("Ahmad","Hussain",1234,2,3,4);

employees[1] = new basepluscomissionemploee("Ali","Hussain",1214,2,3,4);

employees[2] = new basepluscomissionemploee("Babar","Hussain",1200,2,3,4);

employees[3] = new basepluscomissionemploee("Saad","Hussain",1111,2,3,4);

for(int i=0;i<employees.length;i++){

System.out.println(employees[i].earning());

System.out.println("\n");

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

if (employees[i] instanceof basepluscomissionemploee){

basepluscomissionemploee emplpoyees1 =(basepluscomissionemploee ) employees[i];

emplpoyees1.setbaseSalary((10 * (emplpoyees1.getbaseSalaray())));

System.out.println("new base salary with 10% increase is " );


employees[i]=emplpoyees1;

System.out.println(employees[i].earning());

package lab7polymorphism;

/**

* @author Lenovo

*/

public abstract class Employee {

protected String firstName;

protected String lastName;

protected int SSN;

public Employee(){

firstName = null;

lastName = null;

SSN = 0;

public Employee(String fn,String ln, int ssn){

firstName = fn;

lastName = ln;

SSN = ssn;
}

public void display(){

System.out.println("First Name : " + firstName + "Last Name : " + lastName + "SSN : " + SSN);

public abstract double earning();

package lab7polymorphism;

/**

* @author Lenovo

*/

public class basepluscomissionemploee extends comissionEmployee{

private int basicSalary;

public basepluscomissionemploee(){

super();

basicSalary = 0;

public basepluscomissionemploee(String fn,String ln, int ssn, int s, int cr, int bs){

super(fn,ln,ssn,s,cr);

basicSalary = bs;

public void display(){

super.display();

System.out.println("Basic Salary : " + basicSalary);


}

public double earning(){

return super.earning()*basicSalary;

public int getbaseSalaray(){

return basicSalary;

public void setbaseSalary(int a){

basicSalary = a;

package lab7polymorphism;

/**

* @author Lenovo

*/

public class comissionEmployee extends Employee{

private int sales;

private int comissionRate;

public comissionEmployee(){

super();

sales = 0;

comissionRate = 0;

public comissionEmployee(String fn,String ln, int ssn, int s, int cr){


super(fn,ln,ssn);

sales = s;

comissionRate = cr;

public double earning(){

return sales*comissionRate;

public void display(){

super.display();

System.out.println("sales : " + sales + "comissionRate : " + comissionRate);

package lab7polymorphism;

/**

* @author Lenovo

*/

public class hourlyemployee extends Employee{

int hours;

int wagePerHour;

public hourlyemployee(){

super();

hours = 0;

wagePerHour = 0;
}

public hourlyemployee(String fn,String ln, int ssn, int h, int wph){

super(fn,ln,ssn);

hours = h;

wagePerHour = wph;

public double earning(){

return hours*wagePerHour;

public void display(){

super.display();

System.out.println("Hours : " + hours + "wagePerHour : " + wagePerHour);

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package lab7polymorphism;

/**

* @author Lenovo

*/

public class weeklyEmployee extends Employee{


private double weeklysalary;

public weeklyEmployee(){

super();

weeklysalary = 0;

public weeklyEmployee(String fn,String ln, int ssn, double ws){

super(fn,ln,ssn);

weeklysalary = ws;

public double earning(){

return weeklysalary;

public void display(){

super.display();

System.out.println("weeklysalary : " + weeklysalary);

Programn 2

Runner:

package lab7polymorphismq2;

public class Lab7polymorphismq2 {


public static void main(String[] args) {

package1 [] a=new package1[2];


a[0]=new towDayPackage("Ali","Shehbaz","RWP","isb",1,2,3);
a[1]=new overnightPackage("Arbaz","Shehbaz","RWP","isb",2,2,4);

for(int i=0;i<a.length;i++){

System.out.println(a[i].calculateCost());
System.out.println("");

package lab7polymorphismq2;
public abstract class package1 {
protected String senderName;
protected String recieverName;
protected String senderAddress;
protected String recieverAddress;
protected double weightInOunce;
protected double costPerOunce;

public package1(){
senderName = null;
recieverName = null;
senderAddress = null;
recieverAddress = null;
weightInOunce = 0;
costPerOunce = 0;
}
public package1(String sn,String rn,String sa, String ra,double w,double c){
senderName = sn;
recieverName = rn;
senderAddress = sa;
recieverAddress = ra;
weightInOunce = w;
costPerOunce = c;
}
public void display(){
System.out.println("sender name : " + senderName);
System.out.println("recieverName : " + recieverName);
System.out.println("senderAddress : " + senderAddress);
System.out.println("recieverAddress : " + recieverAddress);
System.out.println("weightInOunce : " + weightInOunce);
System.out.println("costPerOunce : " + costPerOunce);
}
public double calculateCost(){return weightInOunce*costPerOunce;}

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package lab7polymorphismq2;

/**
*
* @author Lenovo
*/
public class overnightPackage extends package1{
double additionalFee;
public overnightPackage(){
super();
additionalFee = 0;
}
public overnightPackage(String sn,String rn,String sa, String ra,double w,double c,double af){
super(sn,rn,sa,ra,w,c);
}

public double calculateCost(){


return super.calculateCost()+additionalFee;

package lab7polymorphismq2;

public class towDayPackage extends package1{


private double flatFee;
public towDayPackage(){
super();
flatFee = 0;
}
public towDayPackage(String sn,String rn,String sa, String ra,double w,double c, double ff){
super(sn,rn,sa,ra,w,c);
flatFee = ff;
}
public double calculateCost(){
return super.calculateCost()+flatFee;
}

Program 3

package lab7polymorphismq3;

public class lab7polymorphismq3{

public static void main(String[] args) {

Movie [] mig = new Movie[3];

mig[0] = new Action(112, "Titanic" ,12);

mig[1] = new Comedy(112, "Waar" ,12);

mig[2] = new Drama(112, "PK " ,12);


for ( int i=0; i < mig.length; i++) {

System.out.println(mig[i].calculateFees());

System.out.println(mig[0].Compare_Movies(mig[2]));

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

if (mig[i] instanceof Movie){

Movie emp =(Movie ) mig[i];

emp.SetTitle("Cry");

System.out.println("Movie = " );

mig[i]=emp;

System.out.println(mig[i].GetTitle());

package lab7polymorphismq3;

public abstract class Movie {

protected int ID;

protected String title;

protected int days;

Movie(){

ID =0 ; title = null ; days =0;

}
Movie(int id , String ma , int dd){

ID =id ; title = ma ; days =dd;

public void SetID(int id){

ID =id ;

public void SetTitle(String i){

title =i ;

public void SetDays(int i){

days =i ;

public int GetID(){

return ID;

public String GetTitle(){

return title;

public int GetDays(){

return days;

public Boolean Compare_Movies(Movie mig){

if(title.equalsIgnoreCase(mig.title)){

return true;

}else{

return false;
}

public abstract int calculateFees();

package lab7polymorphismq3;

public class Action extends Movie{

Action(){

Action(int id , String m , int d){

super(id , m , d);

public int calculateFees(){

return (days * 3);

package lab7polymorphismq3;

public class Comedy extends Movie {

Comedy(){

Comedy(int id , String m , int d){

super(id , m , d);
}

public int calculateFees(){

return (days * 2.50);

package lab7polymorphismq3;

public class Drama extends Movie {

Drama(){

Drama(int id , String m , int d){

super(id , m , d);

public int calculateFees(){

return (days * 2);

You might also like