import java.util.Scanner; public class Payroll2 /** This class demonstrates formatted printing * We used placeholders, and .2f to specify decimal digits * and mentioned that column width can also be specified. * */ { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter hours and rate: "); int hoursWorked=scanner.nextInt(); double payPerHour=scanner.nextDouble(); // calculate pay double weeklySalary=0.0; if (hoursWorked > 40) { System.out.println("You worked overtime!"); // now let's calculate weekly salary with 1 1/2 pay for overtime weeklySalary = (hoursWorked-40)*1.5*payPerHour+40*payPerHour; } else { weeklySalary = hoursWorked * payPerHour; } /** this can be done, but we use the else since they are * mutually exclusive. if (hoursWorked <=40) weeklySalary = hoursWorked * payPerHour; ********/ System.out.printf("Your weekly salary is: $%.2f. You worked %d " + "hours at %.2f rate.\n", weeklySalary,hoursWorked, payPerHour); System.out.printf("rate is %.3f. \n",payPerHour); } }