Cse 1223 project 12 (simple clock)


You will be writing portions of a Java class that models a very simple clock.  You will also be provided with two different “front ends” that use this same class as a plug-in – a simple program that loops through the time for a full hour of time, displaying each passing second on your screen, and a slightly more complex program that displays the time in a window and allows you to update it with a click of a button.  If you have coded your clock class correctly, these two programs provided will just work when you run them.


  • Practice with programming fundamentals
    • Variables – Declaration and Assignment
    • Primitive types
    • Branching: if-else if-else syntax, nested if-else syntax
    • Nested while loops
    • Methods – simple functions and procedures
    • Object-oriented programming
  • Works towards the following Course Goals:
    • Competency with using basic coding features of a high-level imperative programming language
    • Competency with writing computer programs to implement given simple algorithms
    • Familiarity with designing simple text-oriented user interfaces

Project 12 Description

This lab is structured differently than previous labs.  For this lab you are provided with three Java files – Project12.java and ClockView.java hold code that you do not need to touch.  You will only be writing code in the file SimpleClock.java.  Create a new project named “Project 12” and import all three of these source code files into your project workspace.  All three of these files must be in the same Project folder, and must all be in the same default namespace in your Eclipse workspace.


Open the SimpleClock.java file.  In this file is a partial implementation of the SimpleClock class.  You must fill in the code for the constructor, as well as for the methods set, tick and time, following the instructions provided for each of these methods in the comments for these methods.

When you think that you have them working, run the Project12.java program.  You should see output like the following:

Clock starts at time: 12:00:00 AM
Clock has been set to time: 11:59:00 PM
TICK: 11:59:01 PM
TICK: 11:59:02 PM
TICK: 11:59:03 PM
TICK: 11:59:04 PM
TICK: 11:59:05 PM
TICK: 11:59:06 PM
TICK: 11:59:07 PM

… Many lines of output like the above …

TICK: 12:58:58 AM
TICK: 12:58:59 AM
TICK: 12:59:00 AM
Clock finally reads: 12:59:00 AM

Once you have that working, try running ClockView.java.  It should pop up a window with a midnight time showing and two buttons – Tick and Reset.  The Tick button should increment the clock by one second, the reset button should set it back to midnight.  Play with this interface to make sure it works as expected.