1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Schach [20]
3 years ago
12

Design two subclasses of Employee…SalariedEmployee and HourlyEmployee. A salaried employee has an annual salary attribute. An ho

urly employee has an hourly pay rate attribute, an hours worked attribute, and an earnings attribute. An hourly employee that works more than 40 hours gets paid at 1.5 times their hourly pay rate. You will decide how to implement constructors, getters, setters, and any other methods that might be necessary. 1. (20 points) Draw a UML diagram for the classes. 2. (80 points) Implement the classes, and write a test program that creates a salaried employee and two hourly employees. One of the hourly employees should have hours worked set to less than 40 and one should have hours worked set to more than 40. The test program should display all attributes for the three employees. To keep things simple, the employee classes don’t need to do any editing.
public class Employee
{
private int empID;
Address address;
Name name;
Date date;

public Employee()
{
}

public Employee(int empID)
{
this.empID = empID;
}

public int getEmpID()
{
return empID;
}

public void setEmpID(int empID)
{
this.empID = empID;
}

public Address getAddress()
{
return address;
}

public void setAddress(Address address)
{
this.address = address;
}

public Name getName()
{
return name;
}

public void setName(Name name)
{
this.name = name;
}

public Date getDate()
{
return date;
}

public void setDate(Date date)
{
this.date = date;
}

}
Computers and Technology
1 answer:
avanturin [10]3 years ago
7 0

Answer:

Complete answer to above question is given below.

Explanation:

Employee.java

import java.util.Date;

public class Employee

{

private int empID;

private Address address;

private Name name;

private Date date;

public Employee()

{

}

public Employee(int empID)

{

this.empID = empID;

}

public int getEmpID()

{

return empID;

}

public void setEmpID(int empID)

{

this.empID = empID;

}

public Address getAddress()

{

return address;

}

public void setAddress(Address address)

{

this.address = address;

}

public Name getName()

{

return name;

}

public void setName(Name name)

{

this.name = name;

}

public Date getDate()

{

return date;

}

public void setDate(Date date)

{

this.date = date;

}

}

Name.java

public class Name {

private String name;

public Name(String name) {

super();

this.name = name;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

}

Address.java

public class Address {

private String addr;

public Address(String addr) {

super();

this.addr = addr;

}

public String getAddr() {

return addr;

}

public void setAddr(String addr) {

this.addr = addr;

}

}

SalariedEmployee.java

public class SalariedEmployee extends Employee {

private double annualSalary;

public SalariedEmployee(double annualSalary) {

super();

this.annualSalary = annualSalary;

}

public double getAnnualSalary() {

return annualSalary;

}

public void setAnnualSalary(double annualSalary) {

this.annualSalary = annualSalary;

}

}

HourlyEmployee.java

public class HourlyEmployee extends Employee {

private double hourlyrate;

private double hours_worked;

private double earnings;

public HourlyEmployee(double hourlyrate, double hours_worked) {

super();

this.hourlyrate = hourlyrate;

this.hours_worked = hours_worked;

}

public double getEarnings()

{

if(hours_worked<=40)

{

earnings=hours_worked*hourlyrate;

}

else if(hours_worked>40)

{

earnings=40*hourlyrate+(hours_worked-40)*hourlyrate*1.5;

}

return earnings;

}

public double getHourlyrate() {

return hourlyrate;

}

public void setHourlyrate(double hourlyrate) {

this.hourlyrate = hourlyrate;

}

public double getHours_worked() {

return hours_worked;

}

public void setHours_worked(double hours_worked) {

this.hours_worked = hours_worked;

}

public void setEarnings(double earnings) {

this.earnings = earnings;

}

Test.java

import java.util.Date;

public class Test {

public static void main(String[] args) {

System.out.println("_____Salaried Employee_____");

SalariedEmployee se=new SalariedEmployee(50000);

se.setEmpID(1234);

se.setName(new Name("Williams"));

se.setAddress(new Address("4,Richmond Street"));

se.setDate(new Date("Oct-11-2014"));

System.out.println("Employee Id :"+se.getEmpID());

System.out.println("Employee Name :"+se.getName().getName());

System.out.println("Employee Address :"+se.getAddress().getAddr());

System.out.println("Joining Date :"+se.getDate());

System.out.println("The Annual Salary :"+se.getAnnualSalary());

System.out.println("\n_____Hourly Employee_____");

HourlyEmployee he1=new HourlyEmployee(8.5,39);

he1.setEmpID(4567);

he1.setName(new Name("Kane"));

he1.setAddress(new Address("5,lake View Road"));

he1.setDate(new Date("Nov-12-2015"));

System.out.println("Employee Id :"+he1.getEmpID());

System.out.println("Employee Name :"+he1.getName().getName());

System.out.println("Employee Address :"+he1.getAddress().getAddr());

System.out.println("Joining Date :"+he1.getDate());

System.out.println("The Earnings Of An HourlyEmployee :"+he1.getEarnings());

System.out.println("\n_____Hourly Employee_____");

HourlyEmployee he2=new HourlyEmployee(9.5,47);

he2.setEmpID(1111);

he2.setName(new Name("John"));

he2.setAddress(new Address("17,Villey Parley Street"));

he2.setDate(new Date("Dec-13-2011"));

System.out.println("Employee Id :"+he2.getEmpID());

System.out.println("Employee Name :"+he2.getName().getName());

System.out.println("Employee Address :"+he2.getAddress().getAddr());

System.out.println("Joining Date :"+he2.getDate());

System.out.println("The Earnings Of An HourlyEmployee :"+he2.getEarnings());

}

}

Output:

_____Salaried Employee_____

Employee Id :1234

Employee Name :Williams

Employee Address :4,Richmond Street

Joining Date :Sat Oct 11 00:00:00 IST 2014

The Annual Salary :50000.0

_____Hourly Employee_____

Employee Id :4567

Employee Name :Kane

Employee Address :5,lake View Road

Joining Date :Thu Nov 12 00:00:00 IST 2015

The Earnings Of An HourlyEmployee :331.5

_____Hourly Employee_____

Employee Id :1111

Employee Name :John

Employee Address :17,Villey Parley Street

Joining Date :Tue Dec 13 00:00:00 IST 2011

The Earnings Of An HourlyEmployee :479.75

You might be interested in
Jason is working on a project that requires him to manage a huge amount of data. The spreadsheet he is working on has data relat
Alinara [238K]

A. use split worksheet view to break the worksheet into different visible sections

<u>Explanation:</u>

Jason is working on a project that requires him to manage a huge amount of data. There are numerous instances when a user has to manage a huge amount of data within a single spreadsheet. It will cause trouble for the user to simultaneously access the data from more than one table in the same sheet.

To deal with this problem, Jason can track and compare this data as he works on the spreadsheet by using the split worksheet view to break the worksheet into different visible sections. The different sections provide a better view of the tables and data extraction and manipulation become easy.

6 0
3 years ago
What is the data rate of a DS0 signal?
djyliett [7]

Answer: 64 Kbps

Explanation:

3 0
2 years ago
The following program is supposed to display a message indicating if the integer entered by the user is even or odd. What is wro
Lapatulllka [165]

Answer:

A. The function definition must appear before the function is called

Explanation:

Given

The above lines of code

Required

Determine the error in the program

In python, functions has be defined before they are called but in this case (of the given program), the function is called before it was defined and this will definitely result in an error;

<em>Hence, option A answers the question</em>

The correct sequence of the program is as follows:

<em>def evenOdd(n): </em>

<em>      if n % 2 == 0: </em>

<em>            return "even" </em>

<em>      return "odd" </em>

<em>num = int(input("Enter an integer: ")) </em>

<em>print("The integer is", evenOdd(num)) </em>

<em />

6 0
2 years ago
In a non-price rationing system, consumers receive goods and services first-come, first served. Give me an example of a time whe
Anna35 [415]

When someone may be giving away something for free.

7 0
2 years ago
Insert a row above the selected row
anastassius [24]
I cants see the "Selected Road" And I cant answer this unless you put that up. Sorry.
6 0
3 years ago
Read 2 more answers
Other questions:
  • Consider a method defined with the header:
    13·1 answer
  • Is a network where connected devices are located within the same building.
    5·2 answers
  • Heelp my brainly stuff says i am 49 but im 11 how to fix?X??
    7·1 answer
  • How to solve a program that accepts a number as input and prints just the decimal portion
    15·2 answers
  • What is technology? *
    10·1 answer
  • Mention five features on the desktop screen​
    5·1 answer
  • What is Celeste? ( This is for my coding class )
    6·2 answers
  • Code: ckg-jbqp-hki<br>only girls join❤️​
    11·2 answers
  • Let x = ["Red", 2.55,"Green", 3,"Black","false"], then solve the following:
    7·1 answer
  • What are the minimum number of bits an address bus must have in a byte addressable memory system containing only 4 KiB of memory
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!