|
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
Was due Feb.19 (Mon) 17:00.
01. class Glarkzle { 02. 03. int MAX_ORDER_SIZE = 25; 04. 05. int numFloobs; 06. String name; 07. 08. Glarkzle( int _numFloobs, String _name ) { 09. |
Note that in the last two items, both situations involve walking up to some particular String object, and asking it a question. In the first case the input happens to be an int, and in the second case it happens to be another String, but otherwise the general task is the same.
A Treasure is a relatively simple class: every treasure has four attributes: a name, a description, a weight (in lbs), and an image-URL. Some examples might be:
name: a small nugget
description: Upon close inspection, the nugget glints of gold!
weight: 0.05 lbs
image-URL: “http://americanhistory.si.edu/dynamic/images/collections_large/98-4804_225px.jpg”name: a fancy pen
description: This pen can write in purple, green, and plaid.
weight: 0.1lbs
image-URL: “”name: chocolate egg
description: The size of an ostrich egg, but made entirely of dark chocolate.
weight: 35 lbs
image-URL: “”
Write the method
toDebugString, which takes no inputs,
and returns a text-representation of the entire object,
intended for programmers to read when debugging.
Think of it as a text-version of BlueJ's Inspect window.
For example,
When writing a debugging-info method, it suffices to only test
this method, instead of testing all of your getters4 individually.
This is only allowed for the case of testing getters, because
they are almost always this simplest of functions.
Of course, your method should be calling the getters, rather
than accessing the fields directly!
(For your test cases, you presumably want to have a treasure with
a shorter description and image-URL than shown here.
You'll need at least two
test cases, since you want to be sure your part (d) works.)
Write a Treasure method boolean isLint(), which returns true if the “treasure” is lint. It suffices to check that its name equals "lint" (ignoring case), and that its weight is exactly 0.0.
(Optional, but will count for towards participation points:)
See http://ru-itec120.pbwiki.com/grue-data-2007spring
(password: “highlander”).
Read the instructions closely,
and then edit the wiki page and add at least two treasures to that page.
If you're curious about where this assignment might be headed, you can check out last semester's assignments The “gRUe” projects shown there are similar to what we'll be writing. (It will be several weeks before we get to part II of this homework, though.)
As usual, include javadoc code for each class you write.
Write these comments before writing the actual code;
the comments will help you focus on what the method does.
PIs have been instructed to not help you on a method,
if you don't have those comments already written.
Similarly, if you are requesting help on a method, and don't
have all other already-written methods called and tested from
your test method, you must do that before receiving later help.
1So the primitive types you need to know are boolean, double, char, int (integers up to ±2 billion (approx)), long(integers up to ±10 quintillion (approx)). The primitive types which you don't need to know are float (single-precision floating-point), short (integers up to ±32767), and byte (integers up to ±128). ↩
2Recall that we've decided named constants should actually be fields, not local variables. ↩
3Note that our method is adding the single-quotes, just like any other punctuation. You can actually embed double-quotes instead, if you prefer, but you have to be sneaky: use the two characters \" in the middle of the String: "ab\"cd" is a string whose length is 5; the third characters is a quotation-mark. The backslash is needed to tell java “The next character is a literal quotation mark, not the end of the String”. ↩
4Note that if were writing setters for this object, we would still need to test those, by interleaving calls to the setters with calls which check whether the fields were actually set. ↩
5If you want to implement some different criterion for what makes one treasure better than another, go ahead. Be sure to document it in your comments. ↩
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
©2007, Ian Barland, Radford University Last modified 2007.Aug.27 (Mon) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |