Uploaded by shameerahmad07

Exercises GUI

advertisement
STIA1014 Exercise on GUI
1. Mamat’s Service Center (MSC) performs some basic automotive maintenance services. The
type of services and its respective charges are listed below:
Service Type
Oil change
Radiator flush
Transmission flush
Inspection
Exhaust replacement
Charge (RM)
8.00
18.00
30.00
15.00
100.00
MSC gives a discount of 10% from the total charge to a client who is a registered member of
its service center. In the figure below is the GUI for the MSC application that allows a user to
calculate the total charge based on the type of services selected by the user. The user needs
to enter the registration number of the vehicle to be serviced in a text field and selects the
type of services that need to be performed. The selection is done by clicking the respective
radio buttons associated with the services as shown in the figure. The user also needs to
specify from the combo box whether the customer is a member of MSC or not. Finally,
when the user clicks the calculate button the program will display the output containing the
vehicle registration number and the calculated total charge (minus discount if it is given) in
the text area.
Based on the description given, write the MSC GUI application above with an event-handling
method for the Calculate button, calcBtn.
2. A local company pays its employees based on the number of hours they work in a week.
The rate per hour depends on the type of the employees as shown below:
Employee Type
A
B
C
Hourly Rate(RM)
150.00
100.00
50.00
If an employee works more than 40 hours, he/she will be paid an overtime rate for the number
of excess hours (above the 40 hours) he/she works. The overtime rate is RM100 per hour
regardless of the type of the employee. An employee who is a member of a worker’s union
must pay union fee of RM50 per week.
The company wants you to write an application that can calculate and print the weekly pay for
its employees. Gross pay is the amount of pay before the union’s fee is deducted and Net pay is
the amount of pay after the union’s fee is deducted. Two sample running of the application’s
GUI are shown below:
The application uses two classes, Employee and PayCalculatorUI, as shown in the UML
class diagrams below:
-
Employee
empID : String
hours : double
type : String
member : boolean
+ Employee(String empID, double hours, String
type, boolean member)
+ computeGrossPayl(): double
+ computeNetPay(double grossPay): double
PayCalculatorUI
//GUI components not shown here
+ PayCalculatorUI ()
- displayBTNActionPerformed (): void
The application PayCalculatorUI creates an Employee object to calculate an employee’s
Gross pay and Net pay. The Employee class constructor requires FOUR (4) parameters which
are:
employee id, hours worked, employee type and membership status. The
computeGrossPay() and computeNetPay() methods calculate and return the employee’s gross
pay and net pay respectively.
The PayCalculatorUI class has:
 Method displayBTNActionPerformed() to handle the ‘Display Pay’ button. This method
reads the four inputs, creates the Employee object and gets the gross pay and net pay by calling
the computeGrossPay()and computeNetPay() methods respectively, and displays the
employee information in the output text area.
 GUI component objects which are shown in the sample running above.
Based on the provided information above, write the Weekly Pay calculator application by
defining the Employee and PayCalculatorUI classes.
Download