go to previous page   go to home page   go to next page hear noise highlighting

Answer:

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: "


A Story Problem

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:

import java.util.Scanner;

public class RestaurantBill
{
  public static void main (String[] args)  

  {
    
    
    double basicCost;

    
    
    

    System.out.println("basic cost: " +  basicCost + " total cost: " + 
         );
  }
}

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.)


QUESTION 8:

Fill in the missing parts.


go to previous page   go to home page   go to next page