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 Clock
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
timestamp.
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 continue by adding small, incremental changes and testing all along the way. (This is sometimes known as Agile Development, Iterative, Incremental Development, or "always have working code.")
MainClassTemplate
class,
find the line that says
public class MainClassTemplate
,
and change the name of the class from MainClassTemplate
to something appropriate (examples: TimestampApp, TimeApp, etc).
Clock
class, below these comments. At the end of the
mini-lab, when you have everything working the way your want, you can
delete these "reminder" comments.
Note:
In Java, the source code for a class is always in a file
with the name of the class and a .java
suffix.
Clock
class along with your previous class
in the class diagram. Double-click on it.
You will be using this class (constructing an object and invoking its methods), not modifying it, so you want to concentrate on the class documentation for the class (information on how to use it) rather than it source code (how does it work internally). If the class window 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.
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.
getHour()
, getMinute()
, getHH()
,
and getMM()
methods. Which would be most useful for
creating a timestamp where hours range from 01 - 12?
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 yet? Why or why not? Does the actual behavior match your expectation? Then invoke call methods on your object, and 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 a random time, rather than the actual
current time.
What method in the Clock class would provide this functionality? Call
that method after you have created the clock object and before you get the
time.
Temporarily report the result of getHour()
on a separate line, so that you can see whether you are getting a
morning or afternoon/evening time. Test enough times that you see
both.
You do not need to submit this mini-lab. You will be adding to it in lab next Tuesday.