In this lab you will add the
Bridge Crossing Problem, which you
first implemented in Java in
Assignment 1, to the
JavaScript implementation
of the
Farmer,
Wolf, Goat, Cabbage and
Water Jug problems developed in the
JavaScript Lecture Notes.
When finished, the main
solve.html page should render as below,
with the user able to solve the bridge problem.
If you originally installed the
Java SE NetBeans bundle you may
not have the module required for JavaScript development.
To find out, click
File and select
New Project... If the
dialog does not show
HTML5 or
HTML/JavaScript
under
Categories, you will need to install the
HTML5
plugin:
- On the NetBeans menu bar click Tools and
select Plugins
- In the Plugins dialog, go to the Available Plugins
tab and search for "HTML5"
- Tick the HTML5 Kit checkbox and click Install
Here is a zipped folder to use for this lab:
solve.zip.
Unzip this file and place the resulting
solve folder in a
location where you will create a NetBeans project.
In NetBeans,
- Under File choose New Project...
- In the dialog, select category HTML5
(or HTML/JavaScript if you have NetBeans 7.3.1 or earlier)
and HTML5 Application with Existing Sources
- For Site Root, browse to the solve folder
- Give the project the name CS 2511 JavaScript
When finished, you should have a
CS 2511 JavaScript project with
a
Site Root folder containing subfolders
js
and
test, and a
solve.html file.
On the NetBeans tool bar, select your desired browser (ignore browsers
with "NetBeans integration").
Right click
solve.html and select
Run File. You will be
brought to a browser web page
like this.
Here is the top-level
solve.html, described in detail in the
JavaScript Lecture Notes:
The
js folder contains all the JavaScript files, including the
subfolders
farmer,
waterjug, and
bridge, and the
top-level
solve.js file, shown below.
All JavaScript files are described in the
JavaScript Lecture Notes.
These files are complete and define objects for the Farmer, Wolf,
Goat, and Cabbage problem.
These files are complete and define objects for the Water Jug
problem.
These files need to be written by you and will define objects for
the
Bridge Crossing problem.
The test pages are provided for you.
The
test folder contains a
bridge subfolder with HTML
files for testing your
BridgeState.js and
BridgeMove.js
files.
These files use the following
assert function:
assert is intended to be called like this:
assert(assertion string);
where
assertion string represents code that should return a
boolean value (e.g.
assert("a < b");).
The code is evaluated, and if the result is not
true an
alert is
displayed.
When you are ready to test your
BridgeState.js file, you can
view
StateTest.html, shown below, in your browser.
The test assumes that you have defined
your
BridgeState constructor function with the same parameter
order as in
Assignment 1.
A successful test will first display the start state, then the state
with
P1 and
P2 crossed, and no assertion errors.
Note that the
alert dialog will not correctly format the string
depicting the state:
This is because
alert does not use a monospace font, and it will
be corrected when the string is displayed in a web
page's
textarea element.
When you are ready to test your
BridgeMove.js file, you can
view
MoveTest.html, shown below, in your browser.
The test assumes that you have defined these variables:
A successful test will display all the states in a solution and no assertion
errors.
- Write BridgeState.js, using FarmerState.js
and WaterJugState.js as models
- Test BridgeState.js by viewing StateTest.html in
your browser
- Write BridgeMove.js, using FarmerMove.js
and WaterJugMove.js as models
- Test BridgeMove.js by viewing MoveTest.html in
your browser
- Write BridgeProblem.js, using FarmerProblem.js
and WaterJugProblem.js as models
- Modify solve.js so that a new BridgeProblem object
is added to the problems array
- Add script elements to solve.html so that the
bridge crossing JavaScript files are loaded
- Test the whole program by viewing solve.html in your
browser
When finished, zip your project folder as
your-login-LEX14.zip.
Email the zip file to your TA.
Successful implementation of:
- BridgeState.js: 3 points
- BridgeMove.js: 5 points
- BridgeProblem.js: 2 points