CSE-1020: Introduction to Computer Science I
York University
Lab Test 2: Coins
2:30pm Thursday 12 November 2009
(Lab-03)
  Welcome to the Lab-test Environment

During the test, you will not be able to access your regular home directory, access, receive, or send e-mail, print, or access the Internet.

The lab tests are closed-book and no aids are allowed.

At the end of your test session, this machine will be converted back to a standard, unrestricted Prism Lab machine. At this time, any files written by you during the test, except those that have been submitted, will not be recoverable. Make sure you submit your code before the end of the test. (Instructions to submit your code are below). If you do not submit your work on time, you will receive a grade of zero. (There are no exceptions.)

Instructions

You have the lab period, 80 minutes, to complete this lab test. The computers will automatically shutdown at the end of the time (e.g., 3:50pm), warning you several minutes in advance. No additional time will be provided, so you must submit your work prior to this; otherwise, there will be no way to recover it (it will be lost), and you will receive a grade of zero (no exceptions).

You are encouraged to submit often during the test. Note that newer submissions overwrite older ones.

Your program will be marked for good style, as well as for running correctly (producing correct output in the correct format).

Submitting Your Work

When you submit a file, you should include at the top of the file your name (surname, given name) and your Prism lab login. These should be placed in a comment so that the file will compile. Note that files which do not compile will receive a large penalty when marked, no matter how small the error that prevented compiling.

Submit the class Coins.java before the time deadline. Here is the command to submit your work:

% submit 1020 labtest2R2.30 Coins.java

Further details regarding the submit command can also be obtained by typing man submit.

Once again, you are encouraged to submit regularly. Newer submissions simply overwrite older ones.

Unlike eCheck assignments, there is partial credit possible. If you are able to finish all aspects of the program (for example, say, input validation was requested but you did not do this), you should still submit it.

Useful APIs

Here are the common APIs that you may access:

 
  The Task

Write a Java application called Coins.java.

Your program should be able to process two kinds of strings. The first kind of string is one or more Canadian coin names separated by *s; for example:

*quarter*loonie*penny*

For such a string, your program should output the value of the sum of the coins (in the previous example the value would be $1.26).

The second kind of string is one or more Canadian coin values in cents separated by *s; for example:

*5*200*10*

For such a string, your program should output the corresponding coin names separated by *s (in the previous example the output would be *nickel*toonie*dime*).

The coin names and values that your program must recognize are shown in the table below:

penny 1
nickel 5
dime 10
quarter   25
loonie 100
toonie 200

Your program should repeatedly prompt a user for a string until the user enters Ctrl-D to indicate the end of input.

You do not have to do input validation.

Your output should look exactly like that indicated in the sample runs below.

Hint: Use the static method named isDigit in the Character class to determine if the user input string is a string of coin names or coin values.

Sample Runs

Here is one sample run of a correctly written program. Note that the text in red is text that the user types. The text in black is what the program types. The '%' represents the prompt from the command-line window (shell).

% java Coins
Enter some coins separated by *s followed by the ENTER key:
*penny*
$0.01

Enter some coins separated by *s followed by the ENTER key:
*5*
*nickel*

Enter some coins separated by *s followed by the ENTER key:
*dime*quarter*quarter*dime*nickel*
$0.75

Enter some coins separated by *s followed by the ENTER key:
*10*10*10*25*200*
*dime*dime*dime*quarter*toonie*

Enter some coins separated by *s followed by the ENTER key:
*loonie*loonie*loonie*
$3.00

Enter some coins separated by *s followed by the ENTER key:
%

Coding

You should use good programming practises as described in the textbook, and your code should conform to the style guide in the textbook. You should comment at least minimally, as by the guidelines.

You should not use any features of Java not covered in the first six chapters of the text. There will be some deduction if you do.