/* Author : Robert Magala */ /* Assignment : Weeks pay */ /* Due Date : June 3, 2003 */ /* Platform : Java 1.4.1 */ /* Summary : Determines the weeks pay */ import javax.swing.JOptionPane; import java.text.DecimalFormat; public class WeeksPay { public static void main(String args[]) { double workTime, hrRate, grossPay = 0, overhr; String empNum, hoursWorked, hourlyRate, result = ""; DecimalFormat currency = new DecimalFormat("$#,###.00"); empNum = JOptionPane.showInputDialog ("Key in employee number or -1 to quit"); result = "Employee # Hours Worked Hourly Rate Gross Pay"; while (!empNum.equals("-1")) { hoursWorked = JOptionPane.showInputDialog ("Input # of hours worked"); hourlyRate = JOptionPane.showInputDialog ("Input the rate of pay"); workTime = Double.parseDouble(hoursWorked); hrRate = Double.parseDouble(hourlyRate); if (workTime > 40) { overhr = workTime - 40; grossPay += overhr * (hrRate*1.5); workTime = workTime - overhr; } grossPay += workTime * hrRate; result += "\n " + empNum +" "+ hoursWorked +" " + currency.format(hrRate) +" "+ currency.format(grossPay); grossPay = 0; empNum = JOptionPane.showInputDialog ("Input the employee number\n or type -1 to quit"); } JOptionPane.showMessageDialog(null, result, "Weekly Pay", JOptionPane.PLAIN_MESSAGE); System.exit(0); } }