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
Can you help me with Computer issues graphic organizer?<br> Will give out brainly
tino4ka555 [31]
Just put for first: coding, graphics and for second : designing, writing
Third?: put all of the abov
6 0
2 years ago
Answer this blank:<br><br> Air enters through the mouth or nose, and travels through the _
Schach [20]
Respiratory system ?. Or esophagus?
5 0
3 years ago
Read 2 more answers
What is a data source in OLE?​
babunello [35]

Answer:

OLE DB Driver for SQL Server uses the term data source for the set of OLE DB interfaces used to establish a link to a data store, such as SQL Server. Creating an instance of the data source object of the provider is the first task of an OLE DB Driver for SQL Server consumer.

Explanation:

hope it helps you and give me a brainliest

6 0
1 year ago
What would be the best thing you could do to prepare yourself to work for a company that has embraced globalization?
kvasek [131]
Learn a foreign language
4 0
2 years ago
Create a program that contains 4 methods / functions... main(), getTestScores(), calcAverage(), and displayAverage(). The main()
jeyben [28]

Answer:

import java.util.Scanner;

public class  num6{

   static int getTestScores(){

       System.out.println("Enter the Score");

       Scanner in = new Scanner(System.in);

       int score = in.nextInt();

       return score;

   }

   static double calcAverage(int score1, int score2, int score3){

       return (score1+score2+score3)/3;

   }

   static void displayAverage(double ave){

       System.out.println("The Average is "+ave);

   }

   public static void main(String[] args) {

       int num1 = getTestScores();

       int num2 = getTestScores();

       int num3 = getTestScores();

       //Calling Calculate Average

       double average = calcAverage(num1,num2,num3);

       //Calling displayAverage

       displayAverage(average);

   }

}

Explanation:

  • Using Java programming Language
  • Create the four methods
  • getTestScores() Uses the Scanner Class to receive an in variable and return it
  • calcAverage() accepts three ints as parameter calculates their average and return it
  • displayAverage() Accepts a double and prints it out with a concatenated string as message
  • In the Main Method, getTestScores is called three times to obtain three numbers from the user
  • calAverage is called and handed the three numbers
  • printAverage is called to output the calculated average
8 0
2 years ago
Other questions:
  • Consider the following class definitions. public class BClass { private int x; public void set(int a) { x = a; } public void pri
    11·1 answer
  • A user saves a password on a website the user logs into from a desktop. Under which circumstances will the password be saved on
    14·1 answer
  • For a loop counter, the appropriate data type would be:
    14·1 answer
  • We can harden a host by: a. Limiting physical access to it b. Turning off unnecessary services c. Installing patches d. All of t
    8·1 answer
  • If a driver who is under the age of 21 is stopped by a law enforcement officer and has a blood alcohol level of 0.02 or greater
    8·1 answer
  • Do you think LinkedIn stands to change the way employers hire? If so, how? Would this be a positive change or a negative one? Ex
    14·1 answer
  • Assignment 4: Evens and Odds<br><br><br> How do I fix this?
    13·1 answer
  • Released in 1976, the Apple I was Apple Computer's first product.<br><br> O True<br> O False
    6·1 answer
  • What is the purpose of heading tags?
    15·1 answer
  • Which of the following is not a reason to choose a community college?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!