Question text in black, answers in blue.
MapGrid
should be and what it
should
do. Since you say that MapGrid
should extend
Grid
, doesn't that mean that the MapGrid
constructor should call the Grid
constructor? But you
said on the assignment that we should rewrite the Grid
constructor...
MapGrid
to extend Grid
, and that means
that every MapGrid
object is also a Grid
object and has the fields that a Grid
object has. But
we need to erase all the arrays that the Grid
constructor made, because we want new ones that are made using the
constructor that takes a seed (like the one on the lecture notes).
MapGrid
constructor doesn't need to
create the arrays that the Grid
constructor made, just
repopulate them with the data made from the new Random
object that has a seed. If you create new fields in
MapGrid
, as you probably want to, the
MapGrid
constructor will need to initialize and create
these.
'A' + i
?
continentTable
method.
markBlob
as a private method, so
mapGrid
can't use it! Should I change the DJW code to make it
protected
, or write an entirely new method in MapGrid
?
Grid
was going to be
extended. I think the best thing to do is to write a new
markBlob
method in MapGrid
, particularly if you want to have it
access the data fields that you are building in MapGrid
.
But if you want to change the markBlob
method in
Grid
to be protected, that's ok too -- we will grade your
code using the Grid
class that is in your edlab
directory, not the code straight from DJW.
visited
, initialized it, and then tried to
access it and got an NullPointerException
. Any idea how that
could happen?
I know that some people have declared visited
in MapGrid
after it was already declared in DJW's Grid
class. That means that there are now two arrays around with the same name --
no good can come of that. It's quite possible that you initialized one of those
arrays and then tried to access the other, especially if you used
this
in one of the two places. Also remember that if you
declared the array in the constructor rather than as a field,
as so many people did on the exam, you might have initialized an array that
ceased to exist when the constructor finished, leaving the other one to cause
your exception.
capitalMap
and continentTable
like you said, but
my MapGrid
class still does not work with MapGridTest
.
We've now put up another driver,
Project3.java, that doesn't refer to
those two methods. But if you said return null
in your stubs,
they won't work in MapGridTest
because that method takes the
output String
objects from your methods and calls their
equals
methods. Replacing return null
with
return "foo"
will solve that problem.
char c
and tried to increment it by saying c = c + 1;
,
but this did not compile. Neither did c = (char) c + 1
. Oddly,
c++;
and c += 1;
both worked, so I can keep coding,
but what was wrong with the other two?
(Thanks to various students in today's lecture.) It's
more or less true that c++;
translates to c = c + 1;
,
but the fomer is smarter about realizing that you want the result to be the
same type that you started with. When you add the char
and the
int
, the result is an int
, and for some reason it
won't do the cast automatically when you use the + sign alone. Using the cast
operator as in your second example would solve the problem, except that
the cast operator has high precedence and applies only to the first thing it
sees. So c = (char) c + 1;
is the same as
c = ((char) c) + 1;
which is just c = c + 1;
because c
is already a char
. But
c = (char) (c + 1); does work.
Last modified 24 October 2012