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

Answer:

The answer is given below:


Adding in a Zero

Here is the complete program.

import java.util.Scanner;
public class TaxProgram
{
  public static void main (String[] args)
  {
    final double taxRate = 0.05;
    Scanner scan = new Scanner( System.in );
    double price;
    double tax ;

    System.out.println("Enter the price:");
    price  = scan.nextDouble();     

    if ( price >= 100.0  )
      tax = price * taxRate;   
    else
      tax = 0.0;

    System.out.println("Item cost: " + price + " Tax: " + tax + " Total: " + (price+tax) );    
  }
}

Is the logic of the program is correct? The expression (price+tax) in the last statement sometimes adds zero to price. This is fine. Adding zero does not change the result.


QUESTION 15:

The user buys a shirt for $100 What will be printed on the monitor?


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