PROGRAM Employee.java //Abstract class Employee abstract class Employee { // Attributes of the class private String firstName; private String lastName; private String SSN; // Getters and setters public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getSSN() { return SSN; } public void setSSN(String sSN) { SSN = sSN; } /* * Abstract method getEarnings, this method will be implemented by all child * classes */ public abstract double getEarnings(); // toString method public String toString() { return "firstName=" + firstName + ", lastName=" + lastName + ", SSN=" + SSN; } // Equals method public boolean equals(Object obj) { // TODO Auto-generated method stub return super.equals(obj); } } BasePlusCommissionEmployee.java

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Plese help me with this:

The following Java program needs to be converted to C++, with .h and cpp files.

 

PROGRAM

Employee.java

//Abstract class Employee abstract class Employee { // Attributes of the class private String firstName; private String lastName; private String SSN; // Getters and setters public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getSSN() { return SSN; } public void setSSN(String sSN) { SSN = sSN; } /* * Abstract method getEarnings, this method will be implemented by all child * classes */ public abstract double getEarnings(); // toString method public String toString() { return "firstName=" + firstName + ", lastName=" + lastName + ", SSN=" + SSN; } // Equals method public boolean equals(Object obj) { // TODO Auto-generated method stub return super.equals(obj); } }

BasePlusCommissionEmployee.java

/*Class BasePlusCommissionEmployee inheriting CommissionEmployee*/ class BasePlusCommissionEmployee extends CommissionEmployee { // Attribute of class private double baseSalary; // Getters and setters of the class public double getBaseSalary() { return baseSalary; } public void setBaseSalary(double baseSalary) { this.baseSalary = baseSalary; } // toString method public String toString() { return "BasePlusCommissionEmployee [" + super.toString() + ", baseSalary=" + baseSalary + "]"; } // equals method public boolean equals(Object obj) { return super.equals(obj); } // overriding abstract method getEarnings public double getEarnings() { return super.getEarnings() + baseSalary; } }

CommissionEmployee.java

/*Class CommissionEmployee inheriting Employee*/ class CommissionEmployee extends Employee { // Attributes of the class private double grossSales; private double commissionRate; // Getter and setter methods public double getGrossSales() { return grossSales; } public void setGrossSales(double grossSales) { this.grossSales = grossSales; } public double getCommissionRate() { return commissionRate; } public void setCommissionRate(double commissionRate) { this.commissionRate = commissionRate; } // toString method public String toString() { return "CommissionEmployee [" + super.toString() + ", grossSales=" + grossSales + ", commissionRate=" + commissionRate + "]"; } // Equals method public boolean equals(Object obj) { // TODO Auto-generated method stub return super.equals(obj); } // overriding abstract method getEarnings public double getEarnings() { return commissionRate * grossSales; } }

HourlyEmployee.java

/*Class HourlyEmployee inheriting Employee*/ class HourlyEmployee extends Employee { // Attributes of the class private double wage; private int hours; // Getter and setter method public double getWage() { return wage; } public void setWage(double wage) { this.wage = wage; } public int getHours() { return hours; } public void setHours(int hours) { this.hours = hours; } // toString Method public String toString() { return "HourlyEmployee [" + super.toString() + ", wage=" + wage + ", hours=" + hours + "]"; } @Override public boolean equals(Object obj) { return super.equals(obj); } // overriding abstract method getEarnings public double getEarnings() { if (hours > 40) { return (hours * wage) + ((hours - 40) * 1.5 * wage); } else { return hours * wage; } } }

SalariedEmployee.java

/*Class SalariedEmployee inheriting Employee*/ class SalariedEmployee extends Employee { // Attribute of the class private double weeklySalary; // Getter and setter methods public double getWeeklySalary() { return weeklySalary; } public void setWeeklySalary(double weeklySalary) { this.weeklySalary = weeklySalary; } // overriding abstract method getEarnings public double getEarnings() { // TODO Auto-generated method stub return weeklySalary; } // toString method public String toString() { return "SalariedEmployee [" + super.toString() + ", weeklySalary=" + weeklySalary + "]"; } // equals method public boolean equals(Object obj) { return super.equals(obj); } }

Main.java

//Class Main public class Main { /* * Main method of the class */ public static void main(String[] args) { // Creating object of salariedEmployee SalariedEmployee salariedEmployee = new SalariedEmployee(); salariedEmployee.setFirstName("Ram"); salariedEmployee.setLastName("Gopal"); salariedEmployee.setSSN("123"); salariedEmployee.setWeeklySalary(10000); // Creating object of CommissionEmployee CommissionEmployee commissionEmployee = new CommissionEmployee(); commissionEmployee.setFirstName("Anand"); commissionEmployee.setLastName("Gopal"); commissionEmployee.setSSN("1234"); commissionEmployee.setCommissionRate(100); commissionEmployee.setGrossSales(20); // Creating object of BasePlusCommissionEmployee BasePlusCommissionEmployee basePlusCommissionEmployee = new BasePlusCommissionEmployee(); basePlusCommissionEmployee.setFirstName("Birla"); basePlusCommissionEmployee.setLastName("Gopal"); basePlusCommissionEmployee.setSSN("1235"); basePlusCommissionEmployee.setCommissionRate(100); basePlusCommissionEmployee.setGrossSales(20); basePlusCommissionEmployee.setBaseSalary(5000); // Creating object of HourlyEmployee HourlyEmployee hourlyEmployee = new HourlyEmployee(); hourlyEmployee.setFirstName("Vijay"); hourlyEmployee.setLastName("Gopal"); hourlyEmployee.setSSN("1236"); hourlyEmployee.setHours(45); hourlyEmployee.setWage(10); // Runtime polymorphism // Calculating payroll using polymorphism. Employee salEmp = salariedEmployee; System.out.println("Salaried Employee\n------------------"); System.out.println(salEmp.toString()); System.out.println(salEmp.getEarnings()); // Calculating payroll using polymorphism. Employee comEmp = commissionEmployee; System.out.println("\nCommission Employee\n----------------"); System.out.println(comEmp.toString()); System.out.println(comEmp.getEarnings()); // Calculating payroll using polymorphism. Employee baseEmp = basePlusCommissionEmployee; System.out.println("\nBasePlusCommission Employee\n----------------"); System.out.println(baseEmp.toString()); System.out.println(baseEmp.getEarnings()); // Calculating payroll using polymorphism. Employee hourlyEmp = hourlyEmployee; System.out.println("\nHourly Employee\n----------------"); System.out.println(hourlyEmp.toString()); System.out.println(hourlyEmp.getEarnings()); } }

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY