/* Java program to compute an employee's gross and net pay for a week. ** A fixed percentage of gross pay is deducted for taxes. ** There is no consideration given to overtime pay. ** Input is simulated using assignment statements (i.e., the input ** values are "hard-coded" within the program). ** Use of procedural decomposition led to the introduction of separate ** methods for computing gross pay, tax, and net pay. Each of these ** methods assigns the computed value to a global variable. This is not ** the preferred way of doing things, but we resort to it because, at ** this point in the course, we have neither parameter passing nor ** functional methods at our disposal. ** ** Author: R. McCloskey ** Date: Sept. 2016 (modified Sept. 2023) */ public class GrossNetPay1 { static final double TAX_RATE = 0.1825; // symbolic constant static double hoursWorked, hourlyWage; // inputs, in a sense static double grossPay, netPay; // outputs static double tax; // auxiliary variable public static void main(String[] args) { hoursWorked = 42.8; // In a contrived fashion, assign values hourlyWage = 14.58; // to the input variables. computeGrossPay(); computeTax(); computeNetPay(); reportResults(); } /* Computes gross pay and assigns the result to the proper global variable. ** Assumes ability to access global variables containing values for hours ** worked and hourly wage. */ private static void computeGrossPay() { grossPay = hoursWorked * hourlyWage; } /* Computes tax and assigns the result to the proper global variable. ** Assumes ability to access global variables containing values for gross ** pay and tax rate. */ private static void computeTax() { tax = grossPay * TAX_RATE; } /* Computes net pay and assigns the result to the proper global variable. ** Assumes ability to access global variables containing values for gross ** pay and tax. */ private static void computeNetPay() { netPay = grossPay - tax; } /* Prints a message reporting the employee's hours worked, hourly wage, ** gross pay, and net pay. Assumes ability to access global variables ** containing the values of these quantities. */ private static void reportResults() { System.out.println(hoursWorked + " hours worked at $" + hourlyWage + " per hour"); System.out.println("yields gross pay of $" + grossPay + "\nand net pay of $" + netPay); } }