Beispiel #1
0
 /** Checkout calculates and print the price for any item that is purchased by quantity. */
 public static void tc00018() {
   System.out.println("GP1-00018 purchased by quantity");
   Basket b;
   Receipt receipt = null;
   Tax tax = new Tax(7.7, new Date(), new Date());
   int loc = 40;
   for (int i = loc; i <= loc + 3; i++) {
     // System.out.println(list.get(i));
     b = list.get(i);
     try {
       if (b.getPaymentType().equals("card")) {
         receipt =
             new Receipt(
                 b.getDate(),
                 b.getItemBasket(),
                 b.getCustomer(),
                 tax,
                 b.getCashback(),
                 b.getCouponList());
       } else if (b.getPaymentType().equals("cash")) {
         receipt =
             new Receipt(
                 b.getDate(), b.getItemBasket(), b.getAmountPaid(), tax, b.getCouponList());
       }
     } catch (NullPointerException e) {
       System.out.println("Empty");
     }
     System.out.println("[TESTING REQ GP1-00018]");
     System.out.println(receipt.printGroceries());
     System.out.println("[END TESTING REQ GP1-00018]");
     // seems to work for F type groceries...
   }
 }
Beispiel #2
0
 /** Checkout processes grocery store items from customer's basket for a given date. */
 public static void tc00001(ArrayList<Basket> list) {
   System.out.println("GP1-00001");
   Basket b;
   Receipt receipt = null;
   Tax tax = new Tax(7.7, new Date(), new Date());
   for (int i = 0; i < 3; i++) {
     // System.out.println(list.get(i));
     b = list.get(i);
     try {
       if (b.getPaymentType().equals("card")) {
         receipt =
             new Receipt(
                 b.getDate(),
                 b.getItemBasket(),
                 b.getCustomer(),
                 tax,
                 b.getCashback(),
                 b.getCouponList());
       } else if (b.getPaymentType().equals("cash")) {
         receipt =
             new Receipt(
                 b.getDate(), b.getItemBasket(), b.getAmountPaid(), tax, b.getCouponList());
       }
     } catch (NullPointerException e) {
       System.out.println("Empty");
     }
     System.out.println("[TESTING REQ GP1-00001]");
     System.out.println(receipt.makeHeader());
     System.out.println(receipt.printGroceries());
     System.out.println("[END TESTING REQ GP1-00001]");
   }
 }
Beispiel #3
0
 /** Checkout calculates and print sales tax for any taxable item in a given customer's basket. */
 public static void tc00016() {
   System.out.println("GP1-00016 calc and pritn sales tax");
   Basket b;
   Receipt receipt = null;
   Tax tax = new Tax(7.7, new Date(), new Date());
   int loc = 30;
   for (int i = loc; i <= loc + 5; i++) {
     // System.out.println(list.get(i));
     b = list.get(i);
     try {
       if (b.getPaymentType().equals("card")) {
         receipt =
             new Receipt(
                 b.getDate(),
                 b.getItemBasket(),
                 b.getCustomer(),
                 tax,
                 b.getCashback(),
                 b.getCouponList());
       } else if (b.getPaymentType().equals("cash")) {
         receipt =
             new Receipt(
                 b.getDate(), b.getItemBasket(), b.getAmountPaid(), tax, b.getCouponList());
       }
     } catch (NullPointerException e) {
       System.out.println("Empty");
     }
     System.out.println("[TESTING REQ GP1-00016]");
     System.out.print(receipt.printGroceries());
     System.out.print(receipt.printTotal());
     System.out.println("[END TESTING REQ GP1-00016]\n");
   }
 }
Beispiel #4
0
 /**
  * Checkout prints the item category code of each item purchased in column thirty-one of the main
  * item purchase line.
  */
 public static void tc00014() {
   System.out.println("GP1-00014 item category code in column 31");
   String test = "|";
   test += StringUtils.repeat(" ", 30);
   System.out.println(test.length());
   test += "X"; // in column 31
   Basket b;
   Receipt receipt = null;
   Tax tax = new Tax(7.7, new Date(), new Date());
   int loc = 34;
   for (int i = loc; i <= loc + 3; i++) {
     // System.out.println(list.get(i));
     b = list.get(i);
     try {
       if (b.getPaymentType().equals("card")) {
         receipt =
             new Receipt(
                 b.getDate(),
                 b.getItemBasket(),
                 b.getCustomer(),
                 tax,
                 b.getCashback(),
                 b.getCouponList());
       } else if (b.getPaymentType().equals("cash")) {
         receipt =
             new Receipt(
                 b.getDate(), b.getItemBasket(), b.getAmountPaid(), tax, b.getCouponList());
       }
     } catch (NullPointerException e) {
       System.out.println("Empty");
     }
     System.out.println("[TESTING REQ GP1-00014]");
     System.out.println(test);
     System.out.print(receipt.printGroceries());
     System.out.println("[END TESTING REQ GP1-00014]\n");
   }
 }
Beispiel #5
0
 /**
  * Checkout prints the name of each item purchased left-justified starting in column five of the
  * main item purchase line.
  */
 public static void tc00012() {
   System.out.println("GP1-00012 print name of each item");
   Basket b;
   Receipt receipt = null;
   Tax tax = new Tax(7.7, new Date(), new Date());
   int loc = 34;
   for (int i = loc; i <= loc + 3; i++) {
     // System.out.println(list.get(i));
     b = list.get(i);
     try {
       if (b.getPaymentType().equals("card")) {
         receipt =
             new Receipt(
                 b.getDate(),
                 b.getItemBasket(),
                 b.getCustomer(),
                 tax,
                 b.getCashback(),
                 b.getCouponList());
       } else if (b.getPaymentType().equals("cash")) {
         receipt =
             new Receipt(
                 b.getDate(), b.getItemBasket(), b.getAmountPaid(), tax, b.getCouponList());
       }
     } catch (NullPointerException e) {
       System.out.println("Empty");
     }
     System.out.println("[TESTING REQ GP1-00011]");
     System.out.println("|    X    "); // X in column 5
     System.out.print(receipt.printGroceries());
     System.out.println("|    X   <-- x in column 5 "); // X in column 5
     System.out.println("[END TESTING REQ GP1-00011]\n");
   }
 }
Beispiel #6
0
  public static void main(String[] args) {

    ArrayList<Customer> testCustomers = new ArrayList<Customer>();
    PopulateCustomers p = new PopulateCustomers();
    try {
      testCustomers = p.populateCustomerList();
    } catch (IOException e) {
      e.printStackTrace();
    }
    //		for(Customer cust:testCustomers){
    //			System.out.println(cust);
    //		}
    Receipt receipt = null;
    try {
      Scan scan = new Scan("SampleInputLarge.txt");

      list = scan.scanFile();
    } catch (IOException | ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    Tax tax = new Tax(7.7, new Date(), new Date());
    for (Basket b : list) {
      // System.out.println(b.toString());
      try {
        if (b.getPaymentType().equals("card")) {
          receipt =
              new Receipt(
                  b.getDate(),
                  b.getItemBasket(),
                  b.getCustomer(),
                  tax,
                  b.getCashback(),
                  b.getCouponList());
        } else if (b.getPaymentType().equals("cash")) {
          receipt =
              new Receipt(
                  b.getDate(), b.getItemBasket(), b.getAmountPaid(), tax, b.getCouponList());
        }
      } catch (NullPointerException e) {
        // System.out.println("Empty");
      }
    }

    // TESTS
    tc00001(list);
    tc00002(list);
    tc00003(); // FAILED
    tc00004();
    tc00006(receipt);
    tc00007(receipt);
    tc00008(receipt);
    tc00009(receipt);
    tc00010(receipt);
    tc00011();
    tc00012();
    tc00013();
    tc00014();
    tc00015();
    tc00016();
    tc00017();
    tc00018();
  }
Beispiel #7
0
 /**
  * Checkout prints out each receipt with a text width that is fixed at forty-two (42) characters.
  */
 public static void tc00004() {
   System.out.println("GP1-00004");
   // not counting the | on each side: so total width is 44 chars
   Basket b;
   Receipt receipt = null;
   Tax tax = new Tax(7.7, new Date(), new Date());
   // easiest way to do this right now is just make a string 44 chars and make sure all columns
   // line up
   // Would be better to have each line as a string and use .length() to compare.....
   String compare = StringUtils.repeat("X", 44);
   for (int i = 0; i < 3; i++) {
     // System.out.println(list.get(i));
     b = list.get(i);
     try {
       if (b.getPaymentType().equals("card")) {
         receipt =
             new Receipt(
                 b.getDate(),
                 b.getItemBasket(),
                 b.getCustomer(),
                 tax,
                 b.getCashback(),
                 b.getCouponList());
       } else if (b.getPaymentType().equals("cash")) {
         receipt =
             new Receipt(
                 b.getDate(), b.getItemBasket(), b.getAmountPaid(), tax, b.getCouponList());
       }
     } catch (NullPointerException e) {
       System.out.println("Empty");
     }
     System.out.println(compare);
     System.out.println(receipt);
     System.out.println(compare);
   }
 }