Java HomeWork

profileglangsing
javahomework.docx

Part I: (Short Answer)

1. In Java, what are the three different ways you can implement an interface?

2. Discuss examples of “is-a” and “has-a” relationships and possible Java implementations.

3. When is it appropriate to use the various techniques for handling exceptions?

4. When is it appropriate to use an applet?

5. Discuss how to convert a GUI application into an applet.

First International Resource Management, Inc. (aka. FIRM) asks you to develop programs to solve the

following problem.

FIRM pays its employees on a weekly basis. FIRM has four types of employees: salaried employees, who are paid a fixed weekly salary regardless of the number of hours worked; hourly employees, who are paid by the hour and receive overtime pay; commission employees, who are paid a percentage of their sales; and salaried-commission employees, who receive a base salary plus a percentage of their sales. FIRM wants to implement a java application that performs its payroll calculations polymorphically. Of course each employ belongs to a department.

Based on the description of the problem and several discussions with the client, a class diagram is agreed upon and the class hierarchy is shown in the diagram. At first, the management wants to see a GUI application about three employee types: HourlyEmployee, SalariedEmployee, and CommissionEmployee.

Development of Classes and an Interface

Employee: abstract super class

Attributes:

· Employee name: String

Methods:

· Constructor: with one parameter of employee name

· Get and set methods for the attribute

· earnings(): Abstract method that will return a double value

SalariedEmployee: subclass of Employee

Additional Attribute:

· weeklySalary: double

Methods:

· Constructor: with two parameters of employee name and weekly salary

· Constructor: with one parameter of employee name, and default salary is $800.

· Get and set methods for weeklySalary

· earnings(): return weekly salary

HourlyEmployee: subclass of Employee

Addition Attributes:

· wage: double

· hours: double

Methods:

· Constructor: with three parameters of employee name, wage, and hours

· Constructor: with two parameters of employee name and hours, default wage is $8.

· Get and set methods for wage and hours

· earnings(): if the employee worked overtime (hours>40), the overtime portion is paid half timemore than regular wage.

CommissionEmployee: subclass of Employee

Additional Attribute:

· grossSales: double

· commissionRate: double

Methods:

· Constructor: with three parameters of employee name, gross sales, and commission rate.

· Constructor: with two parameters of employee name and gross sales, and default rate is 0.05.

· Get and set for grossSales and commissionRate

· earnings(): commission is calculated as gross sales times commission rate.

BasePlusCommissionEmployee: subclass of CommissionEmployee, do not worry about it for this home work.

All the classes also need to have a method to print out pay check, which will show company name, basic information of the employee, and earnings of the current week. An interface class Company is used for the purpose and all the employee types will implement this interface.

Company: interface

Attribute:

· Company name: First International Resource Management, Inc.

Methods:

· tellAboutSelf()

Graphic User Interface

To make things easier at the beginning, only take into account of SalariedEmployee,

CommissionEmployee, and HourlyEmplyee.

You can have your own design of the window interface. Basically, the interface will allow user to inputbasic information of an employee, calculate earnings, and show a paycheck.

· The interface checks the valid input, e.g., name should not be empty, and salary should benumeric, and inputs should be in reasonable range (such as hours is great than 0 and not greatthan 168) so on. For numeric input and valid range, please use Exception handling. You may need to create your exceptions.

· The interface allows user to use default values. If a field is left blank, the program shouldshow appropriate default value.

· Clicking Add will create an employee object and show a successful message.

· After adding an employee, clicking Earn button will show the earning of the employee in amessage.

· Clicking Print will show a message box that contains paycheck information.

· Clicking Clear will reset text fields to be blank.

· Clicking Close will shutdown the program.

Interface for Salary Employee:

After inputting data and clicking Add.

After clicking Earn (please only click Earn after a succesful Add.)

After clicking Print

Interface for Commision Employee:

Interface for Hourly Employee:

When Hours is not valid, a message is shown.

Following information can be used as testing data. When testing your program, try all kinds of things to break it. Then fix it.

Employee

Type

Avery Tolar

Salary

Salary is 1000

Tammy Hemphill

Commission Employee

Gross sales = 14500, default rate

Wayne Tarrance

Hourly employee

Worked 55 hours last week, default wage