Assignemnt #27

Code


  /// Name: Daniel Nguyen
  /// Period: 6
  /// Program Name: Sequencing Program
  /// File Name: Sequencing.java
  /// Date Finished: 9/9/2015
 
  import java.util.Scanner;
  
  public class Sequencing
  {
      public static void main( String[] args )
      {
          // BROKEN
  // Program works after removing zero because it doesn't require to know what price is until after it is input below
          Scanner keyboard = new Scanner(System.in);
         double price, salesTax, total;
 // When removing the zero it says the variable has not been initialized
        
 
         System.out.print( "How much is the purchase price? " );
         price = keyboard.nextDouble();
  salesTax = price * 0.0825;
         total = price + salesTax;
          // program works now because in order the sales tax and total to evaluate the price it first needs to be defined
         System.out.println( "Item price:\t" + price );
         System.out.println( "Sales tax:\t" + salesTax );
         System.out.println( "Total cost:\t" + total );
     }
 }
    

Picture of the output

Assignment 3
BACK HOME NEXT