Question text in black, answers in blue.
The Maze's third field is the array of Cell objects. What it says further down is that the third parameter of the constructor is an array of Strings. The constructor is going to have code to create the array of Cell objects, and it will look at the array of Strings to decide whether to make each cell open or closed. Most of the constructors you have seen are very boring, but in general a constructor may contain whatever code it needs to make the new object according to the specifications in the parameters.
You need to remotely access one of the edlab machines using your account. Exactly how you do this depends on what kind of machine you are using -- the simplest method is from a Unix machine, Linux machine, or the "terminal" of a Mac, using "ssh". Go here, and scroll down to the section on "remote access to edlab machines". Once you are on an edlab machine with your account, place your .java files in the directory called "cs187". And don't mess with the Unix permissions for that directory, or you may prevent us from reading your submission.
Also, how can I check whether my program is right?
I or the TA's can look at your program during office hours. More importantly, if you understand what the program is supposed to do you should be able to write a main methold that will test it on some examples. Your program should be able to create Maze objects using the constructors, display them with the toString method, and create the correct arrays of Cell objects with the moves method.
Yes, for nearly everyone the edlab account has the
same username as their spire email -- so a student with email
dlmoody@student.umass.edu
has username "dlmoody".
Since you're a staff member, there were complications -- I'm glad
they are resolved.
I wasn't able to connect to the edlab machine from my Windows machine with WinSCP. But when I connected with PuTTY, then changed my password at the prompt, WinSCP worked thereafter. I think the mandatory change password prompt causes some problem for WinSCP.
Thanks very much, that may very well help some others.
Maze m = new Maze (3, 4, {"1111", "1001", "1111"});
I got an Invalid variable declaration
message from
Dr. Java. But when I said:
String [ ] s = {"1111", "1001", "1111"});
Maze m = new Maze (3, 4, s);
it worked fine. Did I do something wrong?
No, I did. I forgot that there is no such thing
as an "array constant", only an "array initializer". (See Java
Precisely, page 12.) To use a fixed array as a parameter, you
need to first put it in a variable, then use the variable, as you
discovered. The reason is that an array has to be created, either
with It's very helpful when a student spots an error like this,
especially early in the assignment period. You get an
extra point on the final exam -- thanks!
new
or an assignment statement that sets a
variable. I will correct the assignment page.
First off, I had to look it up, so I
clearly wasn't expecting you to use it. It's a convention for
naming your variables to catch type confusion. As I will say
on Monday, our prime mechanism for
keeping our variables straight is to break our programs into short
methods, with only a few variables each to keep track of at one
time.
You should think a bit about your variable names, and how they
convey information to you and to the reader of your program, but I
don't have any fixed convention to suggest. (There are Java
conventions about where to use capital letters and so forth, which I
hope you saw in your previous course -- please use them.)
There are two purposes to an Exception: (1) give
the user or programmer some useful information when a run-time error
crashes the program, and (2) allow the programmer to include code to
be run in the case of an anticipated abnormal condition. I don't
think there is much on exception handling in 121, so we're only
doing a very simple version of (1) in this project. The
My point in mentioning this exception is that only bad input to
the call is supposed to cause it. If you are not careful about
the boundary of the Maze, your
own method could cause one of these expections with valid input, and
that would be bad.
ArrayIndexOutOfBoundsException
(and, by the way, I got
the name of this wrong on the first version of the assignment -- see
the green correction) is an arithmetic exception generated by Java's
own code whenever a method tries to access an entry of an array that
doesn't exist because it is out of bounds. So you don't have to
generate this exception, and I'm not asking you to handle it -- it
will crash the program with a run-time error, but the user will get
the information as to what kind of error occurred and what the call
stack contained when it did.
No, I just screwed this up. I've gone back over the
assignment so that I always list the x (or horizontal, or east-west) direction
first and then the y (or vertical, or north-south) direction. If you've
written code already, you'll need to change it because the signature is now
different.
You get an extra point on the final exam for catching this mistake -- thanks!
That's right -- you are writing code not knowing necessarily
how it is going to be used, and that is deliberate on my part. The TA's will
write some driver class to run with your classes to test whether your classes
have the right functionality. You, of course, are going to want to write some
kind of driver to test whether you are confident that your code works. Note
that the "type" Cell [ ]
, the output of moves
, has
no toString
method, so you will have to write code that runs over
the elements of the array and prints something to tell what they are. But this
is not part of what you need to submit.
moves
depends on the Maze -- how can I create
this array with a new
statement before I know how big it is?
The easiest thing is to look at the neighbors of the given
Cell twice, once to count the open neighbors and once to put them into the
array. One student suggested another valid solution -- put the neighbor Cells
into an ArrayList
, which expands to include as many elements as
are put into it, then use the toArray
method of that class to
create the array of the right size at the end.
The way to do this is actually described on the Edlab home page here, but it's not that
easy to figure out until you know what you want to do. If you have
a Unix machine (which you do in effect with a Mac, with the Terminal
application) you can use a utility called Another way to move a file from a Mac, in a way more intuitive
for Mac users, is to download a free utility called Fugu.
To move a file from a Windows machine to a Unix machine, you can
use
a free utility called WinSCP.
scp
to move
files to another Unix machine. Here is Navin's description of how
to use scp:
scp foo.java
nsharma@elnux1.cs.umass.edu:/nfs/elsrv4/users3/grad/nsharma/TA/hw1
,
or at least that's what you would do if you were Navin and wanted to
copy the file to the folder
/nfs/elsrv4/users3/grad/nsharma/TA/hw1
. (To find the
Unix name of the directory you want on the Edlab machine, say
"pwd" when you are there.)
The But for this assignment, the TA's will only test the functionality of the
constructors, the toString methods, and Cell
class, for example, has three fields
named x, y, and open. Normally we make these fields private and read and write them only through public methods, traditionally called getX
,
setX
, getY
, setY
, getOpen
, and setOpen
. You should really spell these exactly as I do -- you put "get" or "set" at the beginning, and capitalize the first letter of the field name.
moves
. So you just need
to give those methods names that your own code will use directly. (You may not
need to use all those methods -- my solution used only one of the six methods
in the Cell class.)
That's a good idea, especially after this assignment when we have different projects to keep apart. For this assignment, as long as we can find your classes somewhere in your cs187 folder, it's fine.
Yes, we are happy with either "\r" or "\n". In theory, Java is a totally portable language, in practice not so much...
Thanks, I've fixed the typo above. Fortunately you were knowledgable enough to use the Unix command "pwd" to get the full name of each of the two folders involved, rather than trusting my ability to type them correctly.
You're right, and this was my mistake. We will
still accept solutions that insert either \r's or \n's, but it
should be "\n" and I will correct the program assignment page.
You get an extra point on the final exam for pointing out and
correcting the error.
Last modified 15 September 2011