Advertisement
mmayoub

classes, clock tester, Exercise 01 slide 46

Jul 7th, 2017
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. package class170706;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class ClockTester {
  6.  
  7.     public static void main(String[] args) {
  8.         // create a scanner
  9.         Scanner s = new Scanner(System.in);
  10.  
  11.         // create a clock
  12.         Clock c1 = new Clock();
  13.         System.out.printf("c1 default values are %s\n", c1);
  14.  
  15.         // set clock properties
  16.         do {
  17.             System.out.print("Enter hours (0 t0 23): ");
  18.         } while (!c1.setHours(s.nextInt()));
  19.  
  20.         do {
  21.             System.out.print("Enter minutes (0 to 59): ");
  22.         } while (!c1.setMinutes(s.nextInt()));
  23.  
  24.         do {
  25.             System.out.print("Enter seconds (0 to 59): ");
  26.         } while (!c1.setSeconds(s.nextInt()));
  27.  
  28.         System.out.println("\nc1 updated to " + c1);
  29.  
  30.         // add two seconds
  31.         c1.tick();
  32.         c1.tick();
  33.         System.out.println("\nc1 after two seconds is " + c1);
  34.  
  35.         // reset
  36.         c1.reset();
  37.         System.out.println("c1 after reset is " + c1);
  38.  
  39.     }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement