This mini-lab should be done individually. It is okay to get help from the TAs and/or the instructor if you get stuck, but you should try to do it on your own first.
Tip: You should get into the habit of making backup copies of your work.
In this mini-lab you will be getting the time from a
object and printing a timestamp. You'll be able to use this
functionality next week in Lab 2, where the first step is to generate a
The output of your program should consist of a welcome message and the timestamp. For example,
Welcome to the Timestamp Mini-Lab. Timestamp: 11:45or
Welcome to the Timestamp Mini-Lab. Timestamp: 02:23
Implementation: A good software development practice is to start by writing the smallest amount of code that you can test, test it, then continuing by adding small, incremental changes and testing all along the way. (This is sometimes known as Iterative, Incremental Development or "always have working code.")
Tip: Here are some handy keyboard shortcuts:
Select-All: Command-A (Mac), Control-A (Windows)
Copy: Command-C (Mac), Control-C (Windows)
Paste: Command-V (Mac), Control-V (Windows)
Alternative: Make a copy of the JavaTemplates project from Lab 1 (copy the entire directory) and give it an appropriate name (examples: TimestampML, Time, etc.). Then open the new project in BlueJ, edit the
MainClassTemplateclass, find the line that says
public class MainClassTemplate, and change the name of the class from
MainClassTemplateto something appropriate (examples: TimestampApp, TimeApp, etc). In the
mainmethod, delete the lines of commented-out code that construct and use a
mainmethod should generate a welcome message and a "Program done" message. When you close the source code window, you should see that the name of the class in the class diagram has changed also.
NormalClassTemplateclass, which you do not need for this mini-lab.
Note: In Java, the source code for a class is always in a file with the name of the class and a
Download Clock.java and add it to the folder
containing your project. If you close your project and re-open it, you should
now see the
Clock class along with your previous class
in the class diagram. Double-click on it. If the window that comes up
shows source code instead of documentation, go to the pull-down menu
at the top-right of the window (which should say "Source Code") and choose
"Documentation" to switch to the class documentation.
Focus on the
getMM() methods. Which would be most useful for
creating a timestamp where hours range from 01 - 12?
Note: In BlueJ, you can always switch between the source code and the class documentation for a class using the Source Code/Documentation pull-down menu in the top-right of the source code window.
In your main class, construct a clock object and store it in a variable of the right type. Compile and test your program. Do you expect the program's behavior to be any different? Why or why not? Does the actual behavior match your expectation? Then print a simple timestamp showing the hours and minutes. Compile and test your program again. Does the actual behavior match your expectations?
To test that your timestamp works for a variety of times of day, you
would have to wait for hours between tests. Instead, change your
program to ask the clock to report random times, rather than the actual
current time. Temporarily report the result of
on a separate line, so that you can see that you are getting both
morning and afternoon/evening times. Test enough times that you see
You do not need to submit this mini-lab to Moodle. You will be adding to it in lab next Tuesday.