March 31st
- Lecture 21
Collected Lab 18 from those who finished it. Others need to turn it in by noon tomorrow (Friday).
Distributed printouts of Hand.java and Driver.java from Lab17.
Went over Lab 17 in excrutiating detail
Established some design/coding guidelines in the process
- Declare
for loop control variables
in the loop so that they will be local to the loop
- Where
methods exist to test whether a next element exists, use the method
rather than catching an exception when accessing it fails.
- Avoid
the use of numeric literals in the body of your code. If you think you need one, declare it as
a constant at the top of your method or class. Then if it needs to be altered, it only
has to be altered in 1 place
- When
dealing with hands of cards, since the number of cards in the hand may
vary, use the method .size() to determine the number of cards before
retrieving them.
- Arrays was a class that we
haven’t used before. When you saw
the line Arrays.sort(cards); you should have gone to the java api to
see what it was doing. We learned
it has methods to sort all of the primitive types except boolean and that it has a method
to sort Objects too.
- An if
statement is a selection control structure.
- A loop
statement is an iteration control structure.
- We
talked about the fact the the suit order is clubs, diamonds, hearts,
spades (alphabetical in English).
- When
we tried to print out the Deck
using System.out.println (Deck); the value that was
printed was a hash code representing the address, not the address, and not
the values in the Deck.
- We
discussed that unless the Hand
was printed before the element was removed, after the element was removed,
and after another element was added, it was not possible to say that our
code was correct.
Answered questions about programming assignment #4
- Stubs
and Driver are due on Monday by midnight
using submit... Read the specs carefully on what to include and what to
submit.
- Stubs
should have no code except headers and required return statements with
appropriate values. The more
comments in them the better. The
stubs for Lab 17 are a good model.
Beatles.java (page 405 in our text)
·
We discussed how ArrayList
was declared without specifying the type of item to be in the list.
·
We changed the second item to an int
·
The warning compile message was the same whether
all of the elements inserted into the list were of type String or whether one
of them was an int
·
We added a statement to check whether “Peter”
was in the list before printing it in order to avoid an error
·
We modified Beatles.java
and created Beatles2.java
where we specified the type of item to be in the ArrayList.