cp -r ~max/www-docs/courses/S97/MC28/labs/lab7/code .(note that this command ends with a space and then a period), you will get a subdirectory called code containing all the files. Ask for help with this if you need it.
To compile and run the program, you'll need to work in a shell (terminal) window. First you'll need to change directory into the directory where you have the files, e.g.
cd codeNote that if you log out and log back in, you will need to again to the
cd
command to change to the correct directory.
The first thing to do is to test the program out without yet having made any changes. That way you have a baseline for comparison: if it isn't working, you aren't the one who broke it. To run the program, use the command
java -cs CompuDudsThe first time you do this, it will take quite a while for the program to start up, before it prints out its menu of choices. This is because the Java system is "compiling" your program, i.e., checking it over and translating it into an internal form, which is stores in files ending in
.class
. However, if you run the program
again, it will be much quicker to start, because the compiling is
already done. If you change one of the .java
files and
save it out, then when you next run the java command
given above, it will recompile the file you changed, and so it will
take longer, but not as long as the first time when it needed to
compile all the files.
Now you can start making the necessary changes, and test and debug as you go along. You are to do the following:
ItemList.java
file and saving it out) so that it keeps a running
total price as Items are added and deleted, and simply returns that in
the totalPrice method, rather than adding up all the prices then. The
program's outward behavior should remain unchanged.
.java
Warning 1: Discounting each item by 10% and discounting the total price by 10% may wind up with a total price that doesn't match the sum of the individual prices, due to roundoff.
Warning 2: Because thePrice
is an int
, you
can't say
thePrice = .9 * thePrice;(The problem is that multiplying by .9 results in something that isn't an
int
, and hence can't be stored into thePrice
.)
Instead you can say
thePrice = thePrice * 9 / 10;This works because in Java (unlike Scheme), when the / has an
int
on both its left and righ, it means to take the
integer quotient, and so you wind up with the quotient
by 10 of the product of thePrice and 9.