// CS 3291 Homework #1 // // Name: Your Name Goes Here // // E-mail address: yourname@yourorg // // Time spent on this assignment: about how many hours you spent. // // Description: // // Clock defines a "clock" class in which each object represents // a clock able to display time in hh:mm:ss (am/pm) format. // // Usage: // // See method definitions for usage of individual methods. // // main() tests the other methods: // "java Clock hh mm ss ampm n" does the following: // creates a Clock object c with initial time set to // hh:mm:ss (am if ampm = "am", pm if ampm = "pm"). // invokes showClock() on c to display initial time. // invokes tickClock() and then showClock() on c, n times. // invokes resetClock(hh, mm, ss, ap) and showClock() on c. // (It is assumed that 5 arguments are provided, and that hh, ss, // mm, and n represent integers.) // examples: // "java Clock 11 59 59 am 10" // produces the following output: // 11:59:59 am // 12:00:00 pm // 12:00:01 pm // 12:00:02 pm // 12:00:03 pm // 12:00:04 pm // 12:00:05 pm // 12:00:06 pm // 12:00:07 pm // 12:00:08 pm // 12:00:09 pm // Resetting clock to initial time. // 11:59:59 am // "java Clock 20 0 0 am 10" // produces the following output: // Invalid input; setting to default values. // 12:00:00 am // 12:00:01 am // 12:00:02 am // 12:00:03 am // 12:00:04 am // 12:00:05 am // 12:00:06 am // 12:00:07 am // 12:00:08 am // 12:00:09 am // 12:00:10 am // Resetting clock to initial time. // Invalid input; setting to default values. // 12:00:00 am // public class Clock { // Your declarations go here. < ========== // ---- constructor method ------------------------------------- // set time to hh:mm:ss am/pm (am if ampm = "am", // pm if ampm = "pm") // validate inputs: hh must be between 1 and 12, mm and ss // between 0 and 59, ampm either "am" or "pm" // if input is invalid, print (to standard output) a warning // message and set default value of 12:00:00 am. public Clock (int hh, int mm, int ss, String ampm) { // Your code goes here. < ========== } // ---- other methods ------------------------------------------ // reset clock to hh:mm:ss am/pm (arguments have same meaning // as for constructor above). // validate inputs as for constructor, printing warning and // using defaults if invalid. public void resetClock (int h, int m, int s, String ampm) { // Your code goes here. < ========== } // increment clock by 1 second. // note that the time after 11:59:59 am is 12:00:00 pm, // the time after 11:59:59 pm is 12:00:00 am, and // the time after 12:59:59 am (pm) is 1:00:00 am (pm). public void tickClock () { // Your code goes here. < ========== } // display current value of clock in hh:mm:ss am/pm format // (i.e., write to standard output). // e.g., 11:15:05 am, 2:15:00 pm. public void showClock () { // Your code goes here. < ========== } // ---- main method -------------------------------------------- public static void main(String[] args) { // Your code goes here. < ========== } }