![]() |
![]() |
|
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
return (e.getSong().getLastPlayed().comesBefore( s.getLastPlayed())); |
( : ) {
}
|
( ) {
}
|
/** Count the number of Entries by given certain artist, in a playlist.
* @param ents a playlist (“entries”).
* @param artst The artist to look for.
* @return the number of things in ents which refer to a song by artst.
*/
static int howManyBy( java.util.LinkedList<MusicLibraryEntry> ents, String artst ) {
int numSoFar = 0;
for ( MusicLibraryEntry e : ents ) {
if (e.getSong().get ().equals(artst) ) {
numSoFar =
}
}
}
|
/** Find the shortest song in a playlist.
* @param ents The playlist (“entries”). MUST BE NON-EMPTY.
* @return a shortest song in ents.
*/
static Song shortestSong( java.util.LinkedList<MusicLibraryEntry> ents, String artst ) {
shortestSoFar = ents.get(0).getSong();
for ( MusicLibraryEntry e : ) {
if (e.getSong().get <= .getLength()) {
= e.get ();
}
}
return shortestSoFar;
}
|
/** Find all the copyrighted songs in a playlist.
* @param ents The playlist (“entries”).
* @return All the songs with copyrights within ents.
*/
java.util.LinkedList<Song> allCRs( java.util.LinkedList<MusicLibraryEntry> ents ) {
java.util.LinkedList< > crsSoFar = new ();
for ( e : ) {
if (e.get ().get ) {
crsSoFar.add( .get () );
}
}
return ;
}
|
int i = 2;
int ssf = 0;
while (i < 10) {
ssf = ssf + i;
System.out.println( "i=" + i + "; ssf = " + ssf );
i = i+3;
}
|
Make a copy of your hw10 solution, as a new project hw12.
Part (b), 15pts, due Nov.12 (Mon) in class: Turn in the requested pictures and your documentation. No test cases required for turn-in, as this is I/O-based. (Do test each function before proceeding to the next, of course.) Don't turn in any of the code you wrote. When submitting to WebCT, it's fine to just attach your entire BlueJ folder.
Part (c), 25pts, due Nov.14 (Wed)Nov.16 (Fri)
at the start of class:
As usual,
turn in your source code for
Room,
as well as the code for your updated
Explorer method exploreOnce.
You don't need to turn in the code for the
Treasure method treasureListToString,
as long as you do have
roomListToString in class Room.
Remember, we are now taking off for poor indentation!;
if nothing else, paste into eclipse and use Ctrl-A Ctrl-I.
When submitting to WebCT, it's fine to just attach your entire BlueJ folder.
(1) a small nugget -- Upon close inspection, the nugget glints of gold! (2) a fancy pen -- This pen can write in purple, green, and plaid. (3) chocolate egg -- The size of an ostrich egg, but made entirely of dark chocolate. |
name: Davis 225 lab
description: This room is dark, the only light coming from an eerie screen saver.
items: [a computer, a mouse]
name: Mt. Everest, west ascent.
description: The sun shines bright on the glacier above you.
items: [a chocolate egg].
To think about: Should this field be static? That is, if you have ten different Explorers, do they all have identically the same notion of their current Room? And if an Explorer later moves to a different Room, how will our program represent that? (To think about: What does the picture look like, before-and-after, for the objects involved? You'll need to draw a picture for #4, below.)
Explorer me = new Explorer( "Dora" ); Treasure jc = new Treasure( "Jolt Cola", "An unopened 2liter bottle", 4.4 );4 me.grab(jc) // Note that jc was never actually in the room; we gave it directly to `me`. "You pick up a Jolt Cola." me.inventory() "You are carrying: left pocket: a Jolt Cola -- An unopened 2liter bottle right pocket: lint -- a little fluffy ball" me.look() "Davis 225 lab: This room is dark, the only light coming from an eerie screen saver. There is [a computer, a mouse].5." me.drop |
Once you have this working, the above Code Pad example should be similar, except that items won't disappear — dropping a bottle of cola leaves the room with both a computer and a cola. We might continue:
me.dropLeft() "You have dropped a lint." me.dropLeft() "You have dropped a lint." me.look() "Davis 225 lab: This room is dark, the only light coming from an eerie screen saver. There is [a computer, a mouse, a Jolt Cola, a lint, a lint]." me.grab(1) "You have grabbed a mouse."6 me.look(); "Davis 225 lab: This room is dark, the only light coming from an eerie screen saver. There is [a computer, a Jolt Cola, a lint, a lint]." |
/** Have the user select an item from a list. * @param instruction A message describing what is being selected, e.g. "Choose your favorite treasure:" * @param items The list of Treasures to have the user choose from. The list will not be modified. * @return an index into items, or the sentinel value -1, for no-choice-made. * (The -1 might indicate that the user entered an invalid choice, or * maybe the changed their mind and cancelled the selecting.) * The input is taken from the scanner. */ int select( String instruction, LinkedList<Treasure> items ) |
1 So we can tell that in the example Rooms listed, the one containing two Treasures has had a Treasure added to it, since it was constructed. ↩
2Be sure to make this field static. If it is a regular field, then you are saying that every Room contains a Room inside of it; but of course that Room would then (by your definition) also contain a Room, which would contain …. If you mistakenly do this, BlueJ will make about 1000 recursive calls before spewing out a bunch of red lines saying “stack overflow”. ↩
3Remember that in the Code Pad, you don't want to include a semicolon when making a method call whose result you want to see, like grab and look. But, you must include a semicolon for assignment statements, since they return no result. ↩
4Okay, you can provide the fourth argument of "" to the Treasure constructor if you like. But don't you find it a bit annoying, that in order to indicate “use the default image-URL”, we have to pass in the empty string? We can do better, now that we know about overloading: you can write a second Treasure constructor which only takes three inputs, and uses that default image-URL. And since we're not getting rid of the old four-argument version, it doesn't break any of our existing code or test-cases, woo-hoo! You are exhorted to see the last problem on hw10-soln, to see how to avoid repeating any code between the two constructors. ↩
5If your grab calls drop, then the room will still also contain a lint. ↩
6If you have grab drop a lint, then there will be an additional lint lying on the floor. ↩
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
| ©2007, Ian Barland, Radford University Last modified 2007.Dec.14 (Fri) |
Please mail any suggestions (incl. typos, broken links) to ibarland |
![]() |