I was asked how to upload the files to GL after downloading them to your local machine from this web page.

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.

The course name for 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/.

Java assignment 1

CMSC 331, Fall 2015, Mr. Matuszek

Due date: Friday, October 2, at midnight

In this assignment, you will implement classes that represent a shopping cart, items that can be added to a shopping cart, and coupons that can be used to change the price of items.

You are provided the file CartTest.java, containing several unit tests.

Getting started

To start with, make sure you can run unit tests at all. The following instructions assume that you are logged into gl.umbc.edu. If you are using your own development environment, adjust accordingly.
  1. Download these three files, and store them in the same directory:
  2. Set your CLASSPATH environment variable. This tells Java where to find the JUnit libraries.
  3. Compile the Java file:
  4. Run the unit tests:
You should see output like this:
JUnit version 4.12
Time: 0.004

OK (1 test)

Getting the tests

  1. Next, download the following files:
  2. Attempt to compile them: javac *.java
  3. You should get a ton of errors, starting with these two:
    CartTest.java:11: error: cannot find symbol
                    Item item = new Applesauce();
      symbol:   class Applesauce
      location: class CartTest
    CartTest.java:12: error: cannot find symbol
      symbol:   method add(Item)
      location: variable cart of type Cart
  4. That's to be expected, because you haven't created Applesauce.java yet, and you haven't written the add method in Cart.java yet.
The idea here is that we are doing test-driven development: first we wrote the tests that prove that our classes will work correctly, and then we write the actual code.

Write the code

Read CartTest.java and try to understand what the different classes are expected to do, and how they interact with each other.

Here is a summary of the expected functionality (which you must implement):

To get everything compiling, create all the classes above, with the specified relationships between them. Write all the specified methods, but they don't have to do anything yet.

One tip: Fix the first compiler error first. Often, later errors are duplicates, or are caused by earlier errors.

Getting the unit tests running

Once everything compiles, you can focus on getting the unit tests running.

Reminder: you run a unit test (or, rather, a class full of unit tests) like so:

All of the tests in 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.

Customize your project

Once all the existing tests work, add the following required customizations:

Bonus points

For bonus points, add something more creative and difficult.


You should still demonstrate that your additions work correctly in a separate unit tests file named MyTests.java.


Submitting your project

You will submit your project using the 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).