0% found this document useful (0 votes)
63 views6 pages

Employees: Employee

The document defines classes for different types of employees including Employee, Manager, HourlyEmployee, and HourlyEmployeeWithMobile. It also defines classes for different types of vehicles including Vehicle, Airplane, Boat, and Train. The main method creates sample objects of each class and calls methods to output information about the employees and vehicles.

Uploaded by

omri_hak_1993
Copyright
© Attribution Non-Commercial (BY-NC)
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)
63 views6 pages

Employees: Employee

The document defines classes for different types of employees including Employee, Manager, HourlyEmployee, and HourlyEmployeeWithMobile. It also defines classes for different types of vehicles including Vehicle, Airplane, Boat, and Train. The main method creates sample objects of each class and calls methods to output information about the employees and vehicles.

Uploaded by

omri_hak_1993
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 6

Employees

import unit4.collectionsLib.*;
public class Employee
{
public static final double minsalary=20.1;
private String email;
protected String firstName;
protected String lastName;
public Employee(String name,String lastName){
this.firstName = name;
this.lastName = lastName;
}

public Employee (String email, String firstName, String lastName)


{
this.email=email;
this.firstName=firstName;
this.lastName=lastName;
}
public double calcSalary ()
{
return this.minsalary;
}
public String toString ()
{
return ("email "+ this.email+" firstname "+this.firstName+" last Name
"+this.lastName);
}

public String getEmail()


{
return this.email;
}
}

import unit4.collectionsLib.*;
public class HourlyEmployee extends Employee
{
protected double rate;
protected int hour;

public HourlyEmployee (String firstName, String lastName, double rate,int


hour)
{
super (firstName, lastName);
this.rate=rate;
this.hour=hour;
}
public double calcSalary ()
{
return rate*hour;
}
public String toString ()
{
return (super.toString()+" hours "+this.hour+"rate "+this.rate+" Salary
"+this.calcSalary());
}
}

public class Manager extends Employee


{
private double Salary;
private double Bonus;
public Manager (String firstName, String lastName,double Salary)
{
super ( firstName, lastName);
this.Salary=Salary;
this.Bonus=0;
}
public Manager (String firstName, String lastName,double Salary, String
email)
{
super ( email, firstName, lastName);
this.Salary=Salary;
this.Bonus=0;
}

public void GiveBonus(double Bonus)


{
this.Bonus=Bonus;
}
public double calcSalary()
{
return this.Salary+this.Bonus;
}
public String toString()
{
return "Salary: "+this.calcSalary()+super.toString();
}
}

public class HourlyEmployeeWithMobile extends HourlyEmployee


{
final static int Expensesmobile = 500;
public HourlyEmployeeWithMobile(String firstName, String lastName, double
rate,int hour)
{
super ( firstName, lastName, rate,hour);

}
public double calcSalary()
{
return this.Expensesmobile+super.calcSalary();
}
public String toString()
{
return super.toString();
}
}

MAIN

public class PayrollSystem


{

public static void main(String[] args)


{
Employee[] workers = new Employee[5];
workers[0]=new Employee("Ben","Robins","[email protected]");
workers[1]=new Manager("Jerry","Vanilla",8000.32);
workers[2]=new HourlyEmployee("Hag","Moca", 40.5, 80);
workers[3]=new HourlyEmployeeWithMobile("Mobi","Daz",55.3 , 120);
workers[4]=new Manager("Berry","Cone", 10000,"dd@hhh");

for(int i=0; i<5; i++)


{
System.out.println(workers[i]);
}

for(int i=0; i<5; i++)


{
if(workers[i] instanceof Manager) {
((Manager) workers[i]).GiveBonus(1500);
System.out.println(workers[i]);
}
}
System.out.println(workers[4].getEmail());

}
}
Vehicles

public class Vehicle


{
private String type;
private String way;
private int maxSpeed;
public Vehicle(String type,String way, int maxSpeed )
{
this.type=type;
this.way=way;
this.maxSpeed=maxSpeed;
}
public String toString()
{
return "type: "+this.type+" way: "+this.way+" max Speed "+this.maxSpeed;
}
}

public class Airplane extends Vehicle


{
private int maxHeight;
public Airplane(int maxSpeed, int maxHeight)
{
super("sky", "air", maxSpeed);
this.maxHeight=maxHeight;
}
public String toString()
{
return super.toString()+" Max Height: "+maxHeight;
}
}
public class Boat extends Vehicle
{
public Boat(String way, int maxSpeed)
{
super("water", way, maxSpeed);
}
public String toString()
{
return super.toString();
}
}

MAIN

public class TransportationCompany


{
private Vehicle[]vehicles=new Vehicle[50];
private int counter =0;
public TransportationCompany()
{
}
public void addVehicle(Vehicle v)
{
this.vehicles[counter]=v;
this.counter++;
}
public void display()
{
for(int i=0; i<this.counter; i++)
{
System.out.println((i+1)+":"+this.vehicles[i]);
}
}
public void add(int n)
{
for (int i=0; i<this.counter; i++)
{
if (this.vehicles[i] instanceof Train)
{
((Train)this.vehicles[i]).incnumOfCarriages(n);
}

}
}
}

You might also like