Question

Java Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstractUML Class Diagram: SalaryEmployee -salary: double + constructor (name: String, salary: double) + getPayment(): double +toStriUML Class Diagram HourlyEmployee - hourlyRate: double - hoursWorked: double +constructor (name: String, rate: double, hours:

Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEmployee, HourlyEmployee which extend the Employee class and implements that abstract method. A Salary Employee has a salary, a Commision Employee has a commission rate and total sales, and Hourly Employee as an hourly rate and hours worked Software Architecture: The Employee class is the abstract super class and must be instantiated by one of its concrete subclasses: SalaryEmployee, CommissionEmployee, or HourlyEmployee, which extends it. UML Object Diagram Employee Hourly Employee Salary EmployeeEmployee Commission UML Class Diagram Employee name: String +constructor(name: String) + toString): String +getPayment (): double Italicized class/method names within UML Class Diagram indicate abstract class/methods Employee Constructor Summary: Constructor Description Creates an Employee instance with a given name Employee(String name) Employee Method API Modifier and Type Method and Description void toString() Returns a string containing the name of the employee abstract double getPayment() Returns the wages for this employee (i.e. a paycheck)
UML Class Diagram: SalaryEmployee -salary: double + constructor (name: String, salary: double) + getPayment(): double +toString(): String Italicized class/method names within UML Class Diagram indicate abstract class/methods SalaryEmployee Constructor Summary: Constructor Description Creates a SalaryEmployee instance SalaryEmployee(String name, double salary) SalaryEmployee Method API Modifier and TypeMethod and Description double getPayment() Returns paycheck amount which is salary 12 months/ 2x a month toString() Returns employee text as "%s, salary:$96.02" with name and salary String UML Class Diagram CommissionEmployee -commissionRate:double - totalSales: double +constructor (name: String, rate: double, sales: double) + getPayment(): double +toString(): String Italicized class/method names within UML Class Diagram indicate abstract class/methods CommissionEmployee Constructor Summary CommissionEmployee(String name, double rate, double sales)Creates a CommissionEmployee CommissionEmployee Method API Constructor Description Modifier and Type Method and Description double getPayment() Returns paycheck amount which is commission rate total sale toString() Returns employee text as "%s' commission:%.021% @ $%.O2t sales" with name, rate, sales String
UML Class Diagram HourlyEmployee - hourlyRate: double - hoursWorked: double +constructor (name: String, rate: double, hours: double) + getPayment(): double toString(): String Italicized class/method names within UML Class Diagram indicate abstract class/methods HourlyEmployee Constructor Summary: Description Constructor HourlyEmployee (String name, double rate, double hours) Creates an HourlyEmployee HourlyEmployee Method API Modifier and Type Method and Description double getPayment() Returns paycheck amount which is hourly rate * hours worked toString() Returns employee text as "%s, hourly-$%.02t% @ %.02f hours" with name, rate, hours String Tester Files: Use the TestEmployee.java file to test your implementation. Compare your results with the TestEmployee.txt file Sample Method Calls Sample Method Results Employeenew Employee[3]; "Meg Manager, salary:$50000.001n" "Paycheck: $2083.331n" "Sal Salesman, commission:0.15% @ $3400.00 sales\n" "Paycheck: $510.001n" Timmy Temp, hourly:$10.50 25.00 hoursin" "Paycheck: $262.501n" e[new SalaryEmployee("Meg Manager", 50_000) e[1] new CommissionEmployee ("Sal Salesman", .15, 3400); e[2]new HourlyEmployee("Timmy Temp", 10.50, 25); for (Employee worker e) System.out.println(worker); System . out . printf( "Paycheck: $%.02f\n", worker.getPayment));
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Java Program

abstract class Employee{
   private String name;
   public Employee(String name) {
       this.name=name;
   }
   public String toString() {
       return name;
   }
   abstract public double getpayment();
}
class SalaryEmployee extends Employee{
private double salary;
   public SalaryEmployee(String name,double salary) {
       super(name);
       this.salary = salary;
   }

   @Override
   public double getpayment() {
       return salary/24;
      
   }
   public String toString() {
       return super.toString()+" salary:$"+salary;
   }
  
}
class CommissionEmployee extends Employee{
private double commissionRate;
private double totalSales;
   public CommissionEmployee(String name,double rate,double sales) {
       super(name);
       commissionRate=rate;
       totalSales = sales;
   }

   @Override
   public double getpayment() {
       return commissionRate*totalSales;
      
   }
   public String toString() {
       return super.toString()+" commission:%"+commissionRate+"@ "+totalSales+" sales ";
   }
  
}
class HourlyEmployee extends Employee{
private double hourlyRate;
private double hoursWorked;
   public HourlyEmployee(String name,double rate,double hours) {
       super(name);
       hourlyRate=rate;
       hoursWorked = hours;
   }

   @Override
   public double getpayment() {
       return hourlyRate*hoursWorked;
      
   }
   public String toString() {
       return super.toString()+" hourly:$ "+hourlyRate+" @"+hoursWorked+" hours";
   }
  
}

public class TestEmployee {
   public static void main(String args[]) {
       Employee e[] = new Employee[3];
       e[0] =new SalaryEmployee("Meg Manager",50000);
       e[1] =new CommissionEmployee("Sal Salesman",.15,3400);
       e[2] =new HourlyEmployee("Timmy Temp",10.50,25);
      
       for(Employee worker:e) {
           System.out.println(worker);
           System.out.printf("Paycheck : $%.02f\n",worker.getpayment());
       }
   }
}
//sample output

<terminated> TestEmployee ava Application] C:Program Files Java jdk1.8.0 151 Meg Manager salary: $50000.0 Paycheck $2083.33 S

Add a comment
Know the answer?
Add Answer to:
Java Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEm...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • java language Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectang...

    java language Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...

  • Create an abstract class Employee. Your Employee class should include the following attributes: First name (string)...

    Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings.      Create another class HourlyEmployee that inherits from the abstract Employee class.   HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...

  • Create an abstract class Employee. Your Employee class should include the following attributes: First name (string)...

    Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings.      Create another class HourlyEmployee that inherits from the abstract Employee class.   HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...

  • Add an HourlyPlusCommissionEmployee class to the PayrollSystem app by subclassing an existing class. A HourlyPlusCommissionEmployee is...

    Add an HourlyPlusCommissionEmployee class to the PayrollSystem app by subclassing an existing class. A HourlyPlusCommissionEmployee is a kind of CommissionEmployee with the following differences and specifications: HourlyPlusCommissionEmployee earns money based on 2 separate calculations: commissions are calculated by the CommissionEmployee base class hourly pay is calculated exactly the same as the HourlyEmployee class, but this is not inherited, it must be duplicated in the added class BasePlusCommissionEmployee inherits from CommissionEmployee and includes (duplicates) the details of SalariedEmployee. Use this as...

  • In the processLineOfData method, write the code to handle case "H" of the switch statement such...

    In the processLineOfData method, write the code to handle case "H" of the switch statement such that: • An HourlyEmployee object is created using the firstName, lastName, rate, and hours local variables. Notice that rate and hours need to be converted from String to double. You may use parseDouble method of the Double class as follows: Double.parseDouble(rate) Call the parsePaychecks method in this class passing the Hourly Employee object created in the previous step and the checks variable. Call the...

  • Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string...

    Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string SSN; The Employee class has ▪ a no-arg constructor (a no-arg contructor is a contructor with an empty parameter list): In this no-arg constructor, use “unknown” to initialize all private attributes. ▪ a constructor with parameters for each of the attributes ▪ getter and setter methods for each of the private attributes ▪ a method getFullName() that returns the last name, followed by a...

  • Problem 5: Monster Factory (10 points) (Game Dev) Create a Monster class that maintains a count...

    Problem 5: Monster Factory (10 points) (Game Dev) Create a Monster class that maintains a count of all monsters instantiated and includes a static method that generates a new random monster object. In software engineering, a method that generates new instances of classes based on configuration information is called the Factory pattern. UML Class Diagram: Monster - name: String - health: int - strength: int - xp: int + spawn(type:String): Monster + constructor (name: String, health: int, strength: int, xp:...

  • please write in Java and include the two classes Design a class named Fan (Fan.java) to...

    please write in Java and include the two classes Design a class named Fan (Fan.java) to represent a fan. The class contains: An int field named speed that specifies the speed of the fan. A boolean field named fanStatus that specifies whether the fan is on (default false). A double field named radius that specifies the radius of the fan (default 5). A string field named color that specifies the color of the fan (default blue). A no-arg (default) constructor...

  • In this assignment, you will implement Address and Residence classes. Create a new java project. Part...

    In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT