Source of GroceryTab.java


  1: import java.util.*;
  2: 
  3: public class GroceryTab
  4: {
  5:         public static void main(String[] args)
  6:         {
  7:                 Scanner keyboard = new Scanner(System.in);
  8:                 double[] tab = new double[10];
  9:                 int count = 0;
 10:                 String input;
 11: 
 12:                 System.out.println("This program tally's the contents");
 13:                 System.out.println("of a shcpping cart......\n\n");
 14:                 System.out.print("Enter the price of the item or Q to quit: ");
 15: 
 16:                 input = keyboard.next();
 17: 
 18:                 while(!input.equalsIgnoreCase("Q"))
 19:                 {
 20:                         tab[count] = Double.parseDouble(input);
 21:                         count++;
 22: 
 23:                         System.out.print("Enter the price of the item or Q to quit: ");
 24:                         input = keyboard.next();
 25:                 }
 26: 
 27:                 double total = 0;
 28:                 for(int i=0; i < count; i++)
 29:                         total += tab[i];
 30: 
 31:                 System.out.println("Your total is " + total);
 32:         }
 33: }