This is the last CS2000 exercise sheet.
* @author Derek Bridge 666 firstname.lastname@example.org * @author Sir Hugh Jeegoh 999 email@example.com
sheetG. If you are working in a pair, you should store your program in only one team member's directory. I do not want to find myself collecting in two versions of (supposedly) the same program.
sheetGdirectory contains only the files you want me to mark. Do not leave old versions of the program or versions of other programs in the directory. We will mark all
If you have not already done so, finish sheet F (the blackjack program).
Then, copy your answer from your
directory to your
The basic idea of this exercise is to add password-protection to your Blackjack program.
Arrange things so that I can run your original
program by typing
But to run your
sheetG program, I will type
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
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:
sheetGpart of the program, I am not looking for the three-layer architecture. In fact, quite the opposite! In this new part of the program I want you to use anonymous listeners.
passwordsfile. We will not worry about this within this exercise.
Exception, as well as using classes from the Java library.
JOptionPane.showMessageDialog(null, "Error message", "Window title", JOptionPane.ERROR_MESSAGE);
(If you're really keen, look at the Java library to see what you
should really be putting instead of
There is no Challenge Exercise. You have exams! Get on with some revision!