Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. /*
  2. * MCS 141
  3. * HW 7
  4. * a program that uses the RolloverCounter class to test its functionality
  5. * You don't need to change anything in the program...it is just here to help you test your code in the RolloverCounter
  6. *
  7. When this program is run the output should be:
  8. *************************************************
  9. creating new counters...
  10. creating counter c1 with max value = 5...
  11. creating counter c2 with max value = 3...
  12. creating counter c3 with max value = -2 (this should not work)...
  13. Error creating counter: java.lang.RuntimeException: invalid maximum value
  14.  
  15. incrementing the counts 10 times and printing counts...
  16. c1: 1 c2: 1
  17. c1: 2 c2: 2
  18. c1: 3 c2: 3
  19. c1: 4 c2: 0
  20. c1: 5 c2: 1
  21. c1: 0 c2: 2
  22. c1: 1 c2: 3
  23. c1: 2 c2: 0
  24. c1: 3 c2: 1
  25. c1: 4 c2: 2
  26.  
  27. decrementing the counts 7 times and printint counts...
  28. c1: 3 c2: 1
  29. c1: 2 c2: 0
  30. c1: 1 c2: 3
  31. c1: 0 c2: 2
  32. c1: 5 c2: 1
  33. c1: 4 c2: 0
  34. c1: 3 c2: 3
  35.  
  36. resetting counters...
  37. c1: 0 c2: 0
  38. *****************************************************
  39. */
  40.  
  41. public class CounterTest {
  42. public static void main(String args[]) {
  43. System.out.println("creating new counters...");
  44. System.out.println("creating counter c1 with max value = 5...");
  45. RolloverCounter c1 = new RolloverCounter(5);
  46. System.out.println("creating counter c2 with max value = 3...");
  47. RolloverCounter c2 = new RolloverCounter(3);
  48.  
  49. try {
  50. System.out.println("creating counter c3 with max value = -2 (this should not work)...");
  51. RolloverCounter c3 = new RolloverCounter(-2);
  52. } catch (Exception e) {
  53. System.out.println("Error creating counter: " + e);
  54. }
  55.  
  56. System.out.println("\nincrementing the counts 10 times and printing counts...");
  57. for (int i=1; i<=10; i++) {
  58. c1.increment();
  59. c2.increment();
  60. System.out.println("c1: " + c1 + "\tc2: " + c2);
  61. }
  62.  
  63. System.out.println("\ndecrementing the counts 7 times and printint counts...");
  64. for (int i=1; i<=7; i++) {
  65. c1.decrement();
  66. c2.decrement();
  67. System.out.println("c1: " + c1 + "\tc2: " + c2);
  68. }
  69.  
  70. System.out.println("\nresetting counters...");
  71. c1.reset();
  72. c2.reset();
  73. System.out.println("c1: " + c1 + "\tc2: " + c2);
  74.  
  75. } //end main
  76. } //end CounterTest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement