Skip to content

Commit fcbd32a

Browse files
author
Sarah Akinkunmi
committed
added questions
1 parent 8686a02 commit fcbd32a

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

src/chapter9/employee/CommissionEmployee.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
package chapter9.employee;
22

3+
/*9.14 (Employee Hierarchy) In this chapter, you studied an inheritance hierarchy in which class
4+
BasePlusCommissionEmployee inherited from class CommissionEmployee. However, not all types of employees are
5+
CommissionEmployees. In this exercise, you’ll create a more general Employee superclass that factors out
6+
the attributes and behaviors in class CommissionEmployee that are common to all Employees. The common
7+
attributes and behaviors for all Employees are firstName, lastName, socialSecurityNumber, getFirstName,
8+
getLastName, getSocialSecurityNumber and a portion of method toString. Create a new superclass Employee
9+
that contains these instance variables and methods and a constructor. Next, rewrite class CommissionEmployee
10+
from Section 9.4.5 as a subclass of Employee. Class CommissionEmployee should contain only the instance
11+
variables and methods that are not declared in superclass Employee. Class CommissionEmployee’s constructor
12+
should invoke class Employee’s constructor and CommissionEmployee’s toString method should invoke Employee’s
13+
toString method. Once you’ve completed these modifications, run the CommissionEmployeeTest and
14+
BasePlusCommissionEmployeeTest apps using these new classes to ensure that the apps still display the
15+
same results for a CommissionEmployee object and BasePlusCommissionEmployee object, respectively.
16+
*/
17+
318
public class CommissionEmployee extends Employee{
419
private double grossSales;
520
private double commissionRate;

src/chapter9/employee/CommissionEmployeeTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
package chapter9.employee;
22

3+
/*9.14 (Employee Hierarchy) In this chapter, you studied an inheritance hierarchy in which class
4+
BasePlusCommissionEmployee inherited from class CommissionEmployee. However, not all types of employees are
5+
CommissionEmployees. In this exercise, you’ll create a more general Employee superclass that factors out
6+
the attributes and behaviors in class CommissionEmployee that are common to all Employees. The common
7+
attributes and behaviors for all Employees are firstName, lastName, socialSecurityNumber, getFirstName,
8+
getLastName, getSocialSecurityNumber and a portion of method toString. Create a new superclass Employee
9+
that contains these instance variables and methods and a constructor. Next, rewrite class CommissionEmployee
10+
from Section 9.4.5 as a subclass of Employee. Class CommissionEmployee should contain only the instance
11+
variables and methods that are not declared in superclass Employee. Class CommissionEmployee’s constructor
12+
should invoke class Employee’s constructor and CommissionEmployee’s toString method should invoke Employee’s
13+
toString method. Once you’ve completed these modifications, run the CommissionEmployeeTest and
14+
BasePlusCommissionEmployeeTest apps using these new classes to ensure that the apps still display the
15+
same results for a CommissionEmployee object and BasePlusCommissionEmployee object, respectively.
16+
*/
17+
318
public class CommissionEmployeeTest {
419
public static void main(String[] args) {
520
CommissionEmployee employee = new CommissionEmployee("Sue", "Jones", "222-22-2222", 10000, .06);

src/chapter9/employee/Employee.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
package chapter9.employee;
22

3+
/*9.14 (Employee Hierarchy) In this chapter, you studied an inheritance hierarchy in which class
4+
BasePlusCommissionEmployee inherited from class CommissionEmployee. However, not all types of employees are
5+
CommissionEmployees. In this exercise, you’ll create a more general Employee superclass that factors out
6+
the attributes and behaviors in class CommissionEmployee that are common to all Employees. The common
7+
attributes and behaviors for all Employees are firstName, lastName, socialSecurityNumber, getFirstName,
8+
getLastName, getSocialSecurityNumber and a portion of method toString. Create a new superclass Employee
9+
that contains these instance variables and methods and a constructor. Next, rewrite class CommissionEmployee
10+
from Section 9.4.5 as a subclass of Employee. Class CommissionEmployee should contain only the instance
11+
variables and methods that are not declared in superclass Employee. Class CommissionEmployee’s constructor
12+
should invoke class Employee’s constructor and CommissionEmployee’s toString method should invoke Employee’s
13+
toString method. Once you’ve completed these modifications, run the CommissionEmployeeTest and
14+
BasePlusCommissionEmployeeTest apps using these new classes to ensure that the apps still display the
15+
same results for a CommissionEmployee object and BasePlusCommissionEmployee object, respectively.
16+
*/
17+
318
public class Employee {
419
private String firstName;
520
private String lastName;

src/chapter9/employee/HourlyEmployee.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
package chapter9.employee;
22

3+
/* 9.15 (Creating a New Subclass of Employee) Other types of Employees might include SalariedEmployees who
4+
get paid a fixed weekly salary, PieceWorkers who get paid by the number of pieces they produce or
5+
HourlyEmployees who get paid an hourly wage with time-and-a-half—1.5 times the hourly wage—for hours worked
6+
over 40 hours. Create class HourlyEmployee that inherits from class Employee (Exercise 9.14) and has instance
7+
variable hours (a double) that represents the hours worked, instance variable wage (a double) that represents
8+
the wages per hour, a constructor that takes as arguments a first name, a last name, a social security number,
9+
an hourly wage and the number of hours worked, set and get methods for manipulating the hours and wage, an
10+
earnings method to calculate an HourlyEmployee’s earnings based on the hours worked and a toString method that
11+
returns the HourlyEmployee’s String representation. Method setWage should ensure that wage is nonnegative, and
12+
setHours should ensure that the value of hours is between 0 and 168 (the total number of hours in a week). Use
13+
class HourlyEmployee in a test program that’s similar to the one in Fig. 9.5.
14+
*/
15+
316
public class HourlyEmployee extends Employee{
417
private double hours;
518
private double wages;

src/chapter9/employee/HourlyEmployeeTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
package chapter9.employee;
22

3+
/* 9.15 (Creating a New Subclass of Employee) Other types of Employees might include SalariedEmployees who
4+
get paid a fixed weekly salary, PieceWorkers who get paid by the number of pieces they produce or
5+
HourlyEmployees who get paid an hourly wage with time-and-a-half—1.5 times the hourly wage—for hours worked
6+
over 40 hours. Create class HourlyEmployee that inherits from class Employee (Exercise 9.14) and has instance
7+
variable hours (a double) that represents the hours worked, instance variable wage (a double) that represents
8+
the wages per hour, a constructor that takes as arguments a first name, a last name, a social security number,
9+
an hourly wage and the number of hours worked, set and get methods for manipulating the hours and wage, an
10+
earnings method to calculate an HourlyEmployee’s earnings based on the hours worked and a toString method that
11+
returns the HourlyEmployee’s String representation. Method setWage should ensure that wage is nonnegative, and
12+
setHours should ensure that the value of hours is between 0 and 168 (the total number of hours in a week). Use
13+
class HourlyEmployee in a test program that’s similar to the one in Fig. 9.5.
14+
*/
15+
316
public class HourlyEmployeeTest {
417
public static void main(String[] args) {
518
HourlyEmployee hourlyEmployee = new HourlyEmployee("Sue", "Jones", "222-22-2222", 100, 60);

0 commit comments

Comments
 (0)