Mini-Lab: Simple For Loop
Using a loop to test the Talking Robot
This mini-lab should be done individually. It is okay to get
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 modify your Talking Robot lab project to print
messages repeatedly, to help test that your robot produces a variety of
messages for any given time block, all of which are appropriate for that
- Add a loop to your Talking Robot to print a timestamp and
a randomized, time-sensitive message at least 20 times.
Within the loop, you should
- change the time
- print a timestamp
- print a randomized message appropriate for the current time
- add a blank line to the output to make it easier to read
timestamp/message pairs (you can do this with
- Test that your talking robot generates the correct number
of output "paragraphs", that you are getting a variety of timestamps,
that you get several different messages for each time block, and that
you are putting out a blank line between each message and the
- Be sure to edit the comments in your class as appropriate,
including the class documentation comments at the top of the file.
Providing proper documentation is an
important step towards writing well-structured and reusable programs.
If you have time...
- Instead of testing your program with a large number of random times,
you could test it with specific times. For example, if one of your time
blocks is 2am - 8am, then you could choose to explicitly test times like
1:59, 2:00, 2:01, 7:59, 8:00, 8:01, 8:59, and 9:00
(the times around your time-block boundaries) to make sure that your time
boundaries are working the way you want them to. Look at the class
documentation for the
Clock class to learn how to set up
specific test cases.
Of course, if some of
your messages are generic across time blocks, you will need multiple
tests at each time to increase your chance of getting a time-specific
message for each of your test times. Make sure your loop prints at
least as many messages as your number of defined test cases. (What
happens if your loop keeps going past the number of test cases you have
provided? The class documentation should tell you.)
You do not need to submit this mini-lab to Moodle.