Yes. The last line could be written
System.out.print("Sum: " + (first + second) );
Now the declaration of sum
and the
statement that calculates it can be removed.
The parentheses in (first + second)
are necessary to show that the addition first + second
should be done first, followed by conversion to characters
and concatenation to "Sum: "
This program calculates the total bill
for a restaurant meal.
The program will input the cost of the meal.
To this is added a 20% tip and 6% sales tax.
Use double
for arithmetic.
Here is the program:
Here are the missing parts, but not in order:
(basicCost + basicCost*0.06 + basicCost*0.20) System.out.print("Enter the basic cost: "); Scanner scan = new Scanner( System.in ); basicCost = scan.nextDouble();
Copy these missing parts and paste into the blanks to complete the program. (Copy by highlighting a part with the mouse and hitting control-C. Paste by clicking in a box and hitting control-V.)
Fill in the missing parts.