Advertisement
Guest User

Untitled

a guest
Apr 12th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.*;
  2. public class CustomerTest
  3. {
  4.    public static void main(String[] args)
  5.         {
  6.            double totalSales = 0;
  7.            ArrayList<String> customerList;
  8.            customerList = new ArrayList<String>();
  9.            ArrayList<Double> salesList;
  10.            salesList = new ArrayList<Double>();
  11.            Scanner myScanner = new Scanner(System.in);          
  12.            boolean done = true;    
  13.             do
  14.             {
  15.                 Customer aCustomer = new Customer();                
  16.                 System.out.println("1) Add a new customer \n 2) Print all customers \n 3) Compute and print the total sales \n 4) Quit");
  17.                 int choice = Integer.parseInt(myScanner.nextLine());
  18.                 if (choice == 1)
  19.                 {
  20.                     System.out.print("Add a new customer ");
  21.                     String answer = myScanner.nextLine();
  22.                     aCustomer.setName(answer);                  
  23.                     System.out.print("Enter their sales ");
  24.                     String answer2 = myScanner.nextLine();
  25.                     double answer3 = Double.parseDouble(answer2);
  26.                     aCustomer.setSales(answer3);                    
  27.                      for(int i = 1; i < salesList.size(); i++)
  28.                     {
  29.                      totalSales = totalSales + answer3;  
  30.                     }
  31.                     customerList.add(aCustomer);
  32.                 }
  33.                 else if(choice == 2)
  34.                 {
  35.                     System.out.println("Customers: " + customerList);
  36.                     System.out.println("Sales: " + salesList);
  37.                 }
  38.                 else if(choice == 3)
  39.                 {
  40.                    System.out.println("Total sales: $" + totalSales);
  41.                 }
  42.                 else if(choice == 4)
  43.                 {
  44.                     System.out.println("Goodbye   *Bows gracefully*");
  45.                     done = false;
  46.                 }
  47.                 else
  48.                     System.out.println("Invalid Choice");                        
  49.             }
  50.             while (done);
  51.            System.exit(0);
  52.         }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement