rendered paste body/* File: Payroll.java
* Author: Regina Richards
* Date: February 3, 2012
* Purpose: Chapter 02 Exercise 09 - Page 101
9. Write a class that accepts a user's hourly rate of pay and the number of hours
worked. Display the user's gross pay, the withholding tax (15% of gross pay), and
the net pay (gross pay - withholding). Save the class as Payroll.java.
*/
package payroll;
import javax.swing.JOptionPane;
public class Payroll
{
public static void main(String[] args)
{
//INPUT
String hrText, hwText;
double hourlyRate = 0.0;
double hoursWorked = 0.0;
double grossPay = 0.0;
double whTax = 0.0;
double netPay = 0.0;
//PROCESS (steps)
/*
* 1. Input the hourlyRate as hrText (Scanner or JOption)
* 2. Input hoursWorked as hwText
* 3. Convert the hrText to hourlyRate (Double.parseDouble)
* 4. Convert hwText to hoursWorked
* 5. grossPay = hourlyRate * hoursWorked
* 6. whTax = 0.15 * grossPay
* 7. netPay * grossPay - hwTax
*/
hrText = JOptionPane.showInputDialog(null,"What is your hourly rate?", "Hourly Rate",
JOptionPane.QUESTION_MESSAGE);
hourlyRate = Double.parseDouble(hrText);
hwText = JOptionPane.showInputDialog(null,"How many hours did you work?", "Hours Worked",
JOptionPane.QUESTION_MESSAGE);
hoursWorked = Double.parseDouble(hwText);
grossPay = hourlyRate * hoursWorked;
whTax= 0.15 * grossPay;
netPay = grossPay - whTax;
JOptionPane.showMessageDialog(null, "Gross Pay = $" +
grossPay + "\nWithholding Tax = $" +
whTax + "\nNet Pay = $" + netPay);
//OUTPUT
/* 1. println "Gross Pay = " + grossPay
* 2. Println "Withholding Tax = " + whTax
* 3. Println "Net Pay = " + netPay
*/
JOptionPane.showMessageDialog(null, "Gross Pay = $" +
grossPay + "\nWithholding Tax = $" +
whTax + "\nNet Pay = $" + netPay);
}
}