Advertisement
binibiningtinamoran

TrioTester

May 27th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.98 KB | None | 0 0
  1.  
  2. import java.util.ArrayList;
  3.  
  4.  
  5. public class TrioTester {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         Trio<Integer> numberTrio = new Trio<Integer>(3, 4, 5);
  10.         /*
  11.          * un-comment the line of code below and it should cause a compiler error
  12.           * because trio1 should only accept Strings
  13.          */
  14.         //numberTrio.setItem2("apple");
  15.        
  16.         System.out.println("***TESTING TOSTRING METHOD***");
  17.         System.out.println("Should print a text representation:");
  18.         System.out.println(numberTrio);
  19.        
  20.         System.out.println("\n***TESTING GETTERS AND SETTERS METHOD***");
  21.         System.out.println("Item 1 should be 3: " + numberTrio.getItem1());
  22.         System.out.println("Item 2 should be 4: " + numberTrio.getItem2());
  23.         System.out.println("Item 3 should be 5: " + numberTrio.getItem3());
  24.         System.out.println(numberTrio.toString());
  25.         numberTrio.setItem1(6);
  26.         numberTrio.setItem2(7);
  27.         numberTrio.setItem3(8);
  28.         System.out.println("Item 1 should be 6: " + numberTrio.getItem1());
  29.         System.out.println("Item 2 should be 7: " + numberTrio.getItem2());
  30.         System.out.println("Item 3 should be 8: " + numberTrio.getItem3());
  31.  
  32.         System.out.println(numberTrio.toString());
  33.  
  34.         System.out.println("\n***TESTING HASDUPLICATES METHOD***");
  35.  
  36.         System.out.println("Trio contains duplicates? false: " + numberTrio
  37.         .hasDuplicates());
  38.  
  39.         numberTrio.setItem2(6);
  40.         System.out.println("Trio contains duplicates? true: " + numberTrio.hasDuplicates());
  41.         numberTrio.setItem3(6);
  42.         System.out.println("Trio contains duplicates? true: " + numberTrio.hasDuplicates());
  43.  
  44.         System.out.println("\n***TESTING CONTAINS METHOD***");
  45.         numberTrio.setItem1(1);
  46.         numberTrio.setItem2(1);
  47.         numberTrio.setItem3(1);
  48.         System.out.println("Trio contains how many 1s? 3: " + numberTrio.contains(1));
  49.         numberTrio.setItem1(1);
  50.         System.out.println("Trio contains how many 1s? 3: " + numberTrio.contains(1));
  51.         numberTrio.setItem2(1);
  52.         System.out.println("Trio contains how many 1s? 3: " + numberTrio.contains(1));
  53.         numberTrio.setItem3(10);
  54.         System.out.println("Trio contains how many 10s? 1: " + numberTrio.contains(10));
  55.        
  56.         Trio<String> wordTrio = new Trio<String>("hello");
  57.         wordTrio.setItem2("goodbye");
  58.         wordTrio.setItem3("nice knowing you");
  59.         /*
  60.          * un-comment the line of code below and it should cause a compiler error
  61.          * because wordTrio should only accept Strings
  62.          */
  63.         //wordTrio.setItem2(3);
  64.  
  65.         System.out.println("\n***TESTING CONTAINS METHOD***");
  66.         String testString1 = new String("hello");
  67.         String testString2 = new String("HELLO");
  68.         System.out.println("Trio contains how many hello? 1: " + wordTrio.contains(testString1));
  69.         System.out.println("Trio contains how many HELLO? 0: " + wordTrio.contains(testString2));
  70.         //System.out.println("Contents of wordTrio: " + wordTrio.getItemsList
  71.         // ());
  72.  
  73.         System.out.println("\n***TESTING EQUALS METHOD***");
  74.         Trio<Integer> numberTrio2 = new Trio<Integer>(5, 6, 8);
  75.         Trio<Integer> numberTrio3 = new Trio<Integer>(8, 5, 6);
  76.         System.out.println("Trios the same? true: " + numberTrio2.equals(numberTrio3));
  77.         numberTrio2.setItem2(5);
  78.         System.out.println("Trios the same? true: " + numberTrio2.equals(numberTrio3));
  79.         System.out.println("Trios the same? false: " + numberTrio2.equals(wordTrio));
  80.         System.out.println();
  81.         Trio<Integer> numberTrio4 = new Trio<Integer>(1, 1, 2);
  82.         Trio<Integer> numberTrio5 = new Trio<Integer>(1, 2, 2);
  83.         System.out.println("Trios the same? false: " + numberTrio4.equals(numberTrio5));
  84.         Trio<Integer> numberTrio14 = new Trio<Integer>(1, 2, 1);
  85.         Trio<Integer> numberTrio15 = new Trio<Integer>(1, 1, 2);
  86.         System.out.println("Trios the same? true: " + numberTrio14.equals(numberTrio15));
  87.         Trio<String> wordTrio2 = new Trio<String>(new String("a"), new String("b"), new String("c"));
  88.         Trio<String> wordTrio3 = new Trio<String>(new String("a"), new String("b"), new String("c"));
  89.         System.out.println("Trios the same? true: " + wordTrio2.equals(wordTrio3));
  90.  
  91.  
  92.  
  93.        
  94.     }
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement