I'm in CS140 and trying to solve problems in Practice-It. I'm not sure what else to do for this problem to make it correct. The instructions are, "The following program redundantly repeats the same expressions many times. Modify the program to remove all redundant expressions using variables of appropriate types." I'm just learning how to use integers and am struggling with it so I'm sure I'm missing something simple. I posted the code in its original form below how I tried to solve it. Thanks in advance for any help! :)
// This program computes the total amount owed for a meal,
// assuming 8% tax and a 15% tip.
public class Receipt {
public static void main(String[] args) {
int x=38+40+30;
double y=.08;
double z=.15;
System.out.println("Subtotal:");
System.out.println(x);
System.out.println("Tax:");
System.out.println((x) * y);
System.out.println("Tip:");
System.out.println((x) * z);
System.out.println("Total:");
System.out.println((x) + (x) * y + (x) * z);
}
}
The original problem is below.
// This program computes the total amount owed for a meal,
// assuming 8% tax and a 15% tip.
public class Receipt {
public static void main(String[] args) {
System.out.println("Subtotal:");
System.out.println(38 + 40 + 30);
System.out.println("Tax:");
System.out.println((38 + 40 + 30) * .08);
System.out.println("Tip:");
System.out.println((38 + 40 + 30) * .15);
System.out.println("Total:");
System.out.println(38 + 40 + 30 +
(38 + 40 + 30) * .08 +
(38 + 40 + 30) * .15);
}
}