Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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();
}

}

Java, Programming

  • Category:- Java
  • Reference No.:- M92400495
  • Price:- $10

Priced at Now at $10, Verified Solution

Have any Question?


Related Questions in Java

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

In ruby the hash class inherits from enumerable suggesting

In Ruby, the Hash class inherits from Enumerable, suggesting to a programmer that Hashes are collections. In Java, however, the Map classes are not part of the JCF (Java Collections Framework). For each language, provide ...

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As