Respuesta :
Answer:
The program is:
public class ComputePay {
public static void main(String[] args) {
// Calculate pay at work based on hours worked each day
System.out.println("My total hours worked:");
System.out.println(4 + 5 + 8 + 4);
System.out.println("My hourly salary:");
System.out.println("$8.75");
System.out.println("My total pay:");
System.out.println((4 + 5 + 8 + 4) * 8.75);
System.out.println("My taxes owed:"); // 20% tax
System.out.println((4 + 5 + 8 + 4) 8.75 0.20); } }
Explanation:
The first expression that is being repeated many times is the sum of 4+5+8+4. This sum can be stored in a variable that can be used instead of repeating this expression redundantly. Name this variable as hoursWorked
The value of hourly salary is also being used redundantly. So lets store this in a variable and name this variable as hourlySalary
Here the total pay is basically the product of hours worked and hourly salary. So lets store this value in a variable and names this variable as totalPay
Tax rate here is 20% So this can also be stored in a variable tax
Tax owed is the product of hours worked, hourly salary and and tax rate. So this value can also be stored in a variable and names it as taxOwed
So now the program without redundant expressions is given below:
public class ComputePay {
public static void main(String[] args) {
// Calculate pay at work based on hours worked each day
int hoursWorked = 4+5+8+4;
double hourlySalary = 8.75;
double totalPay = hoursWorked * hourlySalary ;
double tax = 0.20;
double taxOwed = hoursWorked * hourlySalary * tax;
//above statement can also be written as taxOwed = totalPay * tax
System.out.println("My total hours worked:");
System.out.println(hoursWorked);
System.out.println("My hourly salary:");
System.out.println("$" + hourlySalary );
System.out.println("My total pay:");
System.out.println(totalPay);
System.out.println("My taxes owed:"); // 20% tax
System.out.println(taxOwed); } }