Inheritance and polymorphism

Assignment Help JAVA Programming
Reference no: EM131591782

Inheritance and Polymorphism

publicclass Employee {

private String name;
private String department;
privatedoublehourlyRate;

public Employee(String p_name,Stringp_dept, doublep_hourlyRate)
{
name = p_name;
department = p_dept;
hourlyRate= p_hourlyRate;
}


publicvoidsetDepartment(String p_dept)
{
department = p_dept;
}
publicvoidsetHourlyRate(doublep_rate)
{
hourlyRate = p_rate;
}

public String getNameAndDepartment()
{
return "Name:" + name + "\nDepartment:" + department;
}
publicdoubleWeeklyPay(intp_numberOfHoursWorked)
{
if(p_numberOfHoursWorked< 40)
returnp_numberOfHoursWorked * hourlyRate;
else
return 40 * hourlyRate;

}

}

publicclassUnionEmployee
extends Employee
{
privatedouble dues;

publicUnionEmployee(String p_name,Stringp_dept, doublep_hourlyRate,doublep_dues)
{
super(p_name,p_dept,p_hourlyRate);

dues = p_dues;
}

publicvoidsetDues(doublep_dues)
{
dues = p_dues;
}

publicdoubleWeeklyPay(intp_hoursWorked)
{
doubleweeklyPay = 0;
if(p_hoursWorked> 40)
{
weeklyPay = super.WeeklyPay(40);
weeklyPay = weeklyPay + (1.5 * (p_hoursWorked - 40)) - dues;
}
else
weeklyPay = super.WeeklyPay(p_hoursWorked);

returnweeklyPay;

 

}

}


publicclassCommissionedEmployee
extends Employee
{
privatedoublecommissionRate;
privatedoublesalesAmount;

publicCommissionedEmployee(String p_name,Stringp_dept, doublep_hourlyRate,doublep_commissionRate)
{
super(p_name,p_dept,p_hourlyRate);
commissionRate = p_commissionRate;
salesAmount = 0;
}

publicvoidsetCommissionRate(doublep_commissionRate)
{
commissionRate = p_commissionRate;
}

publicvoidsetSalesAmount(doublep_salesAmount)
{
salesAmount = p_salesAmount;
}

publicdoubleWeeklyPay(intp_numberOfHoursWorked)
{
doubleweeklyPay = super.WeeklyPay(p_numberOfHoursWorked);

weeklyPay = weeklyPay + (commissionRate * salesAmount);

returnweeklyPay;
}

}


publicclassTestClass {

/**
* @paramargs
*/
publicstaticvoid main(String[] args) {
// TODO Auto-generated method stub

UnionEmployeeu_Emp = newUnionEmployee("UnionEmp1", "UnionDept1", 100, 50);
CommissionedEmployeec_Emp = newCommissionedEmployee("CommissionEmp2", "Commission Dept2", 100, 50.4);
c_Emp.setSalesAmount(2000);
System.out.println("Displaying Union Employee");
display(u_Emp,20);
display(u_Emp,40);
display(u_Emp,60);

System.out.println("Displaying Commissioned Employee");
display(c_Emp,20);
display(c_Emp,40);
display(c_Emp,60);

}

publicstaticvoid display(Employee p_emp, intp_numberOfHours)
{
System.out.println("Number of Hours:" + p_numberOfHours);
System.out.println(p_emp.getNameAndDepartment());
System.out.println("Weekly Pay:" +p_emp.WeeklyPay(p_numberOfHours));
System.out.println();
}

}

Reference no: EM131591782

Questions Cloud

What you consider to primary threat to survival of watney : Explain what you consider to the primary threat to the survival of Mark Watney on Mars. Be sure to use the fundamental physical and physiological principles.
Managing diversity course project : This month you are to develop a power point presentation on one of the minority groups discussed in chapters 5 - 8.
Discuss the experiences of african american women : How do the experiences and struggles of African women differ from the experiences of African American women
Determine the extent of progress toward completion : What methods are used in practice to determine the extent of progress toward completion? Identify some "input measures" and some "output measures".
Inheritance and polymorphism : Inheritance and Polymorphism
What is the yield to maturity for the bond : What is the yield to maturity for the bond?
Underlying assumptions of the organization culture : What are the basic underlying assumptions of the organization's culture? How do these assumptions influence the culture?
How much revenue and gross profit should hawkins recognize : Hawkins Construction Co. has a $60 million contract to construct a highway overpass and cloverleaf. The total estimated cost for the project is $50 million.
Degree of financial leverage under each of three plans : What is the degree of financial leverage under each of the three plans? compute earnings per share (EPS) before the expansion and under the two alternatives.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd