Conveniently, the web server shares a filesystem with GL, so you can use the Unix/Linux
file copy command, cp
, to copy the files from the web directory on GL to your
project directory on GL, without downloading them from the web page at all.
cp /afs/umbc.edu/users/s/m/smatus1/pub/www/331/java1/*.java /wherever/331/java1/
cp /afs/umbc.edu/users/s/m/smatus1/pub/www/331/java1/* /wherever/331/java1/
The first argument to cp is the path to the source file or files. Note that it ends with a *, meaning that it should copy all the files it finds there. You will end up with a couple files you don't need, but you should also end up with all the .java, .jar. and .sh files. [Oops: previous version ended with *.java, meaning you only got the .java files.]
If you are doing the coding on your local machine, and need to upload the files to GL, you
have a couple choices. If you are using Linux or Mac OS X, you can open Terminal and use scp
,
which is a version of cp
that can copy files securely over a network connection.
The command will look something like
scp -r /Users/steve/workspace/java1/src smatus1@gl.umbc.edu:~smatus1/331/java1/
The -r
flag tells scp to recursively copy the contents of all directories. The first argument is the
location of your project directory on your local machine. The second argument is the address to copy
the files to. It starts with a username (smatus1
, but use yours), then an @
,
then the name of the remote machine (gl.umbc.edu
), then a :
, then the path
to copy the files to (~smatus1/331/java1/
). ~smatus1
is a shorthand
meaning "the home directory of the user smatus1" (but obviously use your own, not mine).
If you are using Windows, I recommend acquiring and learning to use WinSCP.
submit
is cmsc331_smatus1
,
and this project is java1
.
To submit this project: submit cmsc331_smatus1 java1 *.java
I only want the Java files, not the class files, or the jars that you got from me.
(But I do want your copies of the Java files that I provided.)
To check that your files all got submitted: submitls cmsc331_smatus1 java1
The result should look similar to
total 16 drwx------ 2 smatus1 rpc 2048 Mar 2 15:10 . drwx------ 46 smatus1 rpc 2048 Mar 2 14:56 .. -rw------- 1 smatus1 rpc 135 Mar 2 14:34 Applesauce.java -rw------- 1 smatus1 rpc 340 Mar 2 14:34 ApplesauceCoupon.java -rw------- 1 smatus1 rpc 637 Mar 2 14:34 Cart.java -rw------- 1 smatus1 rpc 2468 Mar 2 14:34 CartTest.java -rw------- 1 smatus1 rpc 96 Mar 2 14:34 Chicken.java -rw------- 1 smatus1 rpc 195 Mar 2 14:34 Coupon.java -rw------- 1 smatus1 rpc 53 Mar 2 14:34 Item.java -rw------- 1 smatus1 rpc 48 Mar 2 14:34 Meat.java -rw------- 1 smatus1 rpc 200 Mar 2 14:34 MeatCoupon.java -rwxr-xr-x 1 smatus1 rpc 180 Mar 2 15:11 MyTests.java
General instructions for using submit
can be found at http://www.gl.umbc.edu/submit/.
You are provided the file CartTest.java
, containing several unit tests.
export CLASSPATH=junit.jar:hamcrest-core.jar:.
source bash-commands.sh
setenv CLASSPATH junit.jar:hamcrest-core.jar:.
source csh-commands.sh
javac SimpleTest.java
java org.junit.runner.JUnitCore SimpleTest
run SimpleTest
JUnit version 4.12 . Time: 0.004 OK (1 test)
javac *.java
CartTest.java:11: error: cannot find symbol Item item = new Applesauce(); ^ symbol: class Applesauce location: class CartTest
CartTest.java:12: error: cannot find symbol cart.add(item); ^ symbol: method add(Item) location: variable cart of type Cart
Applesauce.java
yet,
and you haven't written the add
method in Cart.java
yet.
Here is a summary of the expected functionality (which you must implement):
Cart
must provide the methods:
add(Item item)
, which adds an Item
to the cart's internal list of
items. (I gave you the code that creates the list.)
add(Coupon coupon)
, which adds a Coupon
to its internal list of coupons.
(You'll have to create that yourself.)
getItemCount()
, which tells you how many items the cart contains.
Hint: use List methods.
getTotal()
, which tells you the total cost of the items in the cart,
after applying coupons.
Item
is an interface with one method:
public double getPrice()
returns the price of this kind of item.
Coupon
is an interface with one method:
public double getNewPrice(Item item)
Coupon
must implement this method. The method works as follows:
Applesauce
is a kind of Item
.
Meat
is a kind of Item
. It cannot be instantiated directly.
Chicken
is a kind of Meat
.
ApplesauceCoupon
is a kind of Coupon
.
MeatCoupon
is a kind of Coupon
.
One tip: Fix the first compiler error first. Often, later errors are duplicates, or are caused by earlier errors.
Reminder: you run a unit test (or, rather, a class full of unit tests) like so:
java org.junit.runner.JUnitCore CartTest
run CartTest
CartTest.java
should succeed as written, with the exception of
testTotal1
, which you should fix, and applesauceIsNotMeat3()
, which you can ignore.
Chicken is $6.99. Applesauce is $3.80.
MyTests.java
.
Examples:
Meat
whose price is measured by the pound (or kilogram).
Coupon
that would interfere with each other. Ensure that only one is applied.
Coupon
whose acceptance criterion is not a simple instanceof
.
Figure out the best way to implement this without breaking abstraction -- it is okay for coupons to "know"
about different kinds of items, but items should never "know" about coupons.
MyTests.java
.
submit
script, as described at the top of this page.
The project is due by midnight on Friday, October 2 (as in the moment between Friday and Saturday).