Exercise Sheet G


This is the last CS2000 exercise sheet.


Read the whole exercise sheet before you begin. Some important requirements are discussed at the end of the sheet.

Part 1

If you have not already done so, finish sheet F (the blackjack program).

Then, copy your answer from your sheetF directory to your sheetG directory. (NB Copy!)

Part 2

The basic idea of this exercise is to add password-protection to your Blackjack program.

Arrange things so that I can run your original sheetF program by typing

java  BlackjackMain

But to run your sheetG program, I will type

java  PasswordMain

When I do the latter, the following window will appear on the screen:

I will type a username and password into the fields:

When I press Return, your program will search through a binary file (not a text file) called passwords in your sheetG directory. If the username and password that I typed are in that file, then your Blackjack program appears.

Alternatively, if I've never used your system before, I can click the button to register as a new user. In this case, the following appears:

I invent a username and password and I enter them into the fields. (I enter the password twice.)

When I press Return, my username and password are written into the passwords file, and then your Blackjack game appears.

Of course, at various points, things can go wrong. If they do go wrong, dialog boxes containing error messages appear. I only get to play Blackjack if nothing goes wrong. Here are some sample error messages:

Hints & Help

Challenge Exercise

There is no Challenge Exercise. You have exams! Get on with some revision!