Question text in black, answers in blue.
MapGridshould be and what it should do. Since you say that
Grid, doesn't that mean that the
MapGridconstructor should call the
Gridconstructor? But you said on the assignment that we should rewrite the
Grid, and that means that every
MapGridobject is also a
Gridobject and has the fields that a
Gridobject has. But we need to erase all the arrays that the
Gridconstructor made, because we want new ones that are made using the constructor that takes a seed (like the one on the lecture notes).
MapGridconstructor doesn't need to create the arrays that the
Gridconstructor made, just repopulate them with the data made from the new
Randomobject that has a seed. If you create new fields in
MapGrid, as you probably want to, the
MapGridconstructor will need to initialize and create these.
'A' + i?
markBlobas a private method, so
mapGridcan't use it! Should I change the DJW code to make it
protected, or write an entirely new method in
Gridwas going to be extended. I think the best thing to do is to write a new
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
Gridto be protected, that's ok too -- we will grade your code using the
Gridclass 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
MapGrid after it was already declared in DJW's
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
continentTablelike you said, but my
MapGridclass still does not work with
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
String objects from your methods and calls their
equals methods. Replacing
return null with
return "foo" will solve that problem.
char cand tried to increment it by saying
c = c + 1;, but this did not compile. Neither did
c = (char) c + 1. Oddly,
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
c = (char) c + 1; is the same as
c = ((char) c) + 1; which is just
c = c + 1;
c is already a
c = (char) (c + 1); does work.
Last modified 24 October 2012