Advertisement
kmahadev

Time2Tester

Aug 5th, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Time2Tester {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner kb = new Scanner(System.in);
  8. char usrChoice = 'y';
  9. int h = 0, m = 0, s = 0;
  10. Time2 time1 = new Time2();
  11. Time2 tLocal;
  12.  
  13. while ( (usrChoice == 'y') || (usrChoice == 'Y') ){
  14.  
  15. System.out.println("Pick an action:");
  16. System.out.println("\n\t1: Create a new Time object." +
  17. "\n\t2: Add time to your Time object." +
  18. "\n\t3: To Display the time." +
  19. "\n\t4: To get the Hour." +
  20. "\n\t5: To get the Minute." +
  21. "\n\t6: To get teh Second." +
  22. "\n\t7: To exit.");
  23. System.out.print("\nYour Choice [1-7]: ");
  24. int choice = kb.nextInt();
  25.  
  26. switch(choice) {
  27.  
  28. case 1:
  29. System.out.println("You chose to Create a new Time Object:\n");
  30. System.out.print("Enter Hour: ");
  31. h = kb.nextInt();
  32. System.out.print("Enter Minute: ");
  33. m = kb.nextInt();
  34. System.out.print("Enter Second: ");
  35. s = kb.nextInt();
  36. tLocal = new Time2(h, m, s);
  37. time1.UpdateTime(tLocal);
  38. System.out.println("The Time is: " + time1);
  39. break;
  40.  
  41. case 2:
  42. System.out.println("You chose to Add to a Time Object:\n");
  43. System.out.println("Current time is: " + time1);
  44. System.out.print("Enter Hours to add: ");
  45. h = kb.nextInt();
  46. System.out.print("Enter Minutes to add: ");
  47. m = kb.nextInt();
  48. System.out.print("Enter Seconds to add: ");
  49. s = kb.nextInt();
  50. tLocal = new Time2(time1);
  51. tLocal.addTime(h, m, s);
  52. time1.UpdateTime(tLocal);
  53. System.out.println("The Time is: " + time1);
  54. break;
  55.  
  56. case 3:
  57. System.out.println("Current (updated) time is: " + time1);
  58. break;
  59.  
  60. case 4:
  61. System.out.println("The hour is " + time1.getHour());
  62. break;
  63. case 5:
  64. System.out.println("The minute is " + time1.getMinute());
  65. break;
  66. case 6:
  67. System.out.print("The second is " + time1.getSeconds());
  68. break;
  69.  
  70. case 7:
  71. System.out.println("You Chose to Exit:\n");
  72. break;
  73.  
  74. default:
  75. System.out.println("Invalid choice:\n");
  76. System.out.println("Program Exiting\n");
  77. break;
  78. }
  79. System.out.print("Do you wish to continue? (y/n): ");
  80. usrChoice = kb.next().charAt(0);
  81. }
  82.  
  83. System.out.println("Program Exiting...\n");
  84. }
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement