CSCI 201: Intro to Programming (Java)

Lab 3: Working with class Clock

Lab Task I

Write a Java class Clock for dealing with the day time represented by hours, minutes, and seconds. This class should NOT have method main().

public class Clock
{
  Rest of your code here
}

Your class must have the following features:

Compile your code and fix possible errors.


Lab Task II

Add another class TestClock to the project with a main() method. For this right-click on the package containing class Clock in NetBeans IDE and use the New menu option to create a new class with main method.

public class TestClock
{
  public static void main(String[] args)
  {
    Rest of your code here
  }
}

The program should:

Compile and run your code.


Lab Task III

Extend your code by appending to it instructions instantiating a Clock object by using three integers (hours, minutes, seconds) read from the keyboard.

int hours = instance of class Scanner.nextInt();
int minutes = instance of class Scanner.nextInt();
int seconds = instance of class Scanner.nextInt();
Clock c2 = new Clock(hours, minutes, seconds);

Then tick the clock ten times, printing the time after each tick.

Use the following values for the Clock object in your tests:

(0:0:0) (0:0:59) (0:1:0) (0:59:59) (1:0:0) (23:59:59)

Note: (24:0:0) is not a valid Clock value.


Lab Task IV (if you wish a challenge)