Advertisement
creech42

Untitled

Nov 14th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.19 KB | None | 0 0
  1. /***********************************************************************
  2.  * >>>>>> TESTER for class ShoppingList --- This code is complete <<<<<<
  3.  *
  4.  * --------------- Below is the output from this tester ----------------
  5.  * Shopping list = apples
  6.  * Shopping list = apples, spam
  7.  * Shopping list = apples, spam, broccoli
  8.  * Shopping list = apples, broccoli
  9.  * Shopping list = apples, broccoli
  10.  * Shopping list = apples
  11.  * Shopping list = apples
  12.  * Shopping list = apples, Twinkies
  13.  * Shopping list = Twinkies
  14.  * Shopping list =
  15.  * Shopping list = Cheez Whiz
  16.  * Shopping list = Cheez Whiz, bread
  17.  * Shopping list = Cheez Whiz
  18.  * Shopping list = Cheez Whiz
  19.  *****************************************************************/
  20. public class ShoppingListTester
  21. {
  22.    public static void check(ShoppingList list, String check) {
  23.        System.out.print("shopping list = "+list);
  24.        
  25.        if (list.toString().equals(check)) {
  26.            System.out.println(" <<CORRECT>>");
  27.         }
  28.         else {
  29.            System.out.println(" <<ERROR!>>");
  30.         }
  31.            
  32.    }
  33.    
  34.    public static void main(String args[])
  35.    {
  36.        ShoppingList Creech = new ShoppingList("");
  37.        Creech.addItem("apples");
  38.        check(Creech,"apples");
  39.        Creech.addItem("spam");
  40.        check(Creech,"apples, spam");
  41.        Creech.addItem("broccoli");
  42.        check(Creech,"apples, spam, broccoli");
  43.        Creech.removeItem("spam");
  44.        check(Creech,"apples, broccoli");
  45.        Creech.addItem("apples");
  46.        check(Creech,"apples, broccoli");
  47.        Creech.removeItem("broccoli");
  48.        check(Creech,"apples");
  49.        Creech.removeItem("chicken");
  50.        check(Creech,"apples");
  51.        Creech.addItem("Twinkies");
  52.        check(Creech,"apples, Twinkies");
  53.        Creech.removeItem("apples");
  54.        check(Creech,"Twinkies");
  55.        Creech.removeItem("Twinkies");
  56.        check(Creech,"");
  57.        Creech.addItem("Cheez Whiz");
  58.        check(Creech,"Cheez Whiz");
  59.        Creech.addItem("bread");
  60.        check(Creech,"Cheez Whiz, bread");
  61.        Creech.removeItem("bread");
  62.        check(Creech,"Cheez Whiz");
  63.        Creech.removeItem("Twinkies");
  64.        check(Creech,"Cheez Whiz");
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement