Overview You will be writing portions of a Java class that models a very simple
ID: 3711226 • Letter: O
Question
Overview
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.
Objectives
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.
Project12.java
http://web.cse.ohio-state.edu/cse1223/currentsem/projects/Project12.java
ClockView.java
http://web.cse.ohio-state.edu/cse1223/currentsem/projects/ClockView.java
SimpleClock.java
http://web.cse.ohio-state.edu/cse1223/currentsem/projects/SimpleClock.java
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.
Explanation / Answer
Hi Dear,
Please find my implementation.
Output:
Clock starts at time: 12:00:00AM
Clock has been set to time: 11:59:00PM
TICK: 11:59:01PM
TICK: 11:59:02PM
TICK: 11:59:03PM
TICK: 11:59:04PM
TICK: 11:59:05PM
TICK: 11:59:06PM
TICK: 11:59:07PM
TICK: 11:59:08PM
TICK: 11:59:09PM
TICK: 11:59:10PM
TICK: 11:59:11PM
TICK: 11:59:12PM
TICK: 11:59:13PM
TICK: 11:59:14PM
TICK: 11:59:15PM
TICK: 11:59:16PM
TICK: 11:59:17PM
TICK: 11:59:18PM
TICK: 11:59:19PM
TICK: 11:59:20PM
TICK: 11:59:21PM
TICK: 11:59:22PM
TICK: 11:59:23PM
TICK: 11:59:24PM
TICK: 11:59:25PM
TICK: 11:59:26PM
TICK: 11:59:27PM
TICK: 11:59:28PM
TICK: 11:59:29PM
TICK: 11:59:30PM
TICK: 11:59:31PM
TICK: 11:59:32PM
TICK: 11:59:33PM
TICK: 11:59:34PM
TICK: 11:59:35PM
TICK: 11:59:36PM
TICK: 11:59:37PM
TICK: 11:59:38PM
TICK: 11:59:39PM
TICK: 11:59:40PM
TICK: 11:59:41PM
TICK: 11:59:42PM
TICK: 11:59:43PM
TICK: 11:59:44PM
TICK: 11:59:45PM
TICK: 11:59:46PM
TICK: 11:59:47PM
TICK: 11:59:48PM
TICK: 11:59:49PM
TICK: 11:59:50PM
TICK: 11:59:51PM
TICK: 11:59:52PM
TICK: 11:59:53PM
TICK: 11:59:54PM
TICK: 11:59:55PM
TICK: 11:59:56PM
TICK: 11:59:57PM
TICK: 11:59:58PM
TICK: 11:59:59PM
TICK: 12:00:00AM
TICK: 12:00:01AM
TICK: 12:00:02AM
TICK: 12:00:03AM
TICK: 12:00:04AM
TICK: 12:00:05AM
TICK: 12:00:06AM
TICK: 12:00:07AM
TICK: 12:00:08AM
TICK: 12:00:09AM
TICK: 12:00:10AM
TICK: 12:00:11AM
TICK: 12:00:12AM
TICK: 12:00:13AM
TICK: 12:00:14AM
TICK: 12:00:15AM
TICK: 12:00:16AM
TICK: 12:00:17AM
TICK: 12:00:18AM
TICK: 12:00:19AM
TICK: 12:00:20AM
TICK: 12:00:21AM
TICK: 12:00:22AM
TICK: 12:00:23AM
TICK: 12:00:24AM
TICK: 12:00:25AM
TICK: 12:00:26AM
TICK: 12:00:27AM
TICK: 12:00:28AM
TICK: 12:00:29AM
TICK: 12:00:30AM
TICK: 12:00:31AM
TICK: 12:00:32AM
TICK: 12:00:33AM
TICK: 12:00:34AM
TICK: 12:00:35AM
TICK: 12:00:36AM
TICK: 12:00:37AM
TICK: 12:00:38AM
TICK: 12:00:39AM
TICK: 12:00:40AM
TICK: 12:00:41AM
TICK: 12:00:42AM
TICK: 12:00:43AM
TICK: 12:00:44AM
TICK: 12:00:45AM
TICK: 12:00:46AM
TICK: 12:00:47AM
TICK: 12:00:48AM
TICK: 12:00:49AM
TICK: 12:00:50AM
TICK: 12:00:51AM
TICK: 12:00:52AM
TICK: 12:00:53AM
TICK: 12:00:54AM
TICK: 12:00:55AM
TICK: 12:00:56AM
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.