Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Time2Tester {
- public static void main(String[] args) {
- Scanner kb = new Scanner(System.in);
- char usrChoice = 'y';
- int h = 0, m = 0, s = 0;
- Time2 time1 = new Time2();
- Time2 tLocal;
- while ( (usrChoice == 'y') || (usrChoice == 'Y') ){
- System.out.println("Pick an action:");
- System.out.println("\n\t1: Create a new Time object." +
- "\n\t2: Add time to your Time object." +
- "\n\t3: To Display the time." +
- "\n\t4: To get the Hour." +
- "\n\t5: To get the Minute." +
- "\n\t6: To get teh Second." +
- "\n\t7: To exit.");
- System.out.print("\nYour Choice [1-7]: ");
- int choice = kb.nextInt();
- switch(choice) {
- case 1:
- System.out.println("You chose to Create a new Time Object:\n");
- System.out.print("Enter Hour: ");
- h = kb.nextInt();
- System.out.print("Enter Minute: ");
- m = kb.nextInt();
- System.out.print("Enter Second: ");
- s = kb.nextInt();
- tLocal = new Time2(h, m, s);
- time1.UpdateTime(tLocal);
- System.out.println("The Time is: " + time1);
- break;
- case 2:
- System.out.println("You chose to Add to a Time Object:\n");
- System.out.println("Current time is: " + time1);
- System.out.print("Enter Hours to add: ");
- h = kb.nextInt();
- System.out.print("Enter Minutes to add: ");
- m = kb.nextInt();
- System.out.print("Enter Seconds to add: ");
- s = kb.nextInt();
- tLocal = new Time2(time1);
- tLocal.addTime(h, m, s);
- time1.UpdateTime(tLocal);
- System.out.println("The Time is: " + time1);
- break;
- case 3:
- System.out.println("Current (updated) time is: " + time1);
- break;
- case 4:
- System.out.println("The hour is " + time1.getHour());
- break;
- case 5:
- System.out.println("The minute is " + time1.getMinute());
- break;
- case 6:
- System.out.print("The second is " + time1.getSeconds());
- break;
- case 7:
- System.out.println("You Chose to Exit:\n");
- break;
- default:
- System.out.println("Invalid choice:\n");
- System.out.println("Program Exiting\n");
- break;
- }
- System.out.print("Do you wish to continue? (y/n): ");
- usrChoice = kb.next().charAt(0);
- }
- System.out.println("Program Exiting...\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement