$24
Submission note: Your .zip file should contain only .java files and your Assignment Information Sheet. There should be no project files or project subdirectories in the .zip file. Also, your TA must be able to compile your program from the command line using the javac command. Test your files to make sure this will work (especially if you use an IDE such as NetBeans for development). If the TA cannot compile your program you will receive minimal credit!
Introduction:
In Assignment 2 you implemented a very simple word game that allowed a player to guess at scrambled words (anagrams). In this assignment you will improve your game in several ways to make it more useful and playable.
Previously on CS 0401 . . .
Before starting this assignment, read over Assignment 2 carefully so that you are again familiar with all of its requirements and specifications. Much of this assignment will be similar or even identical to Assignment 2.
What's New:
You will improve on Assignment 2 in the following ways:
Scramble2 class: In Assignment 2 your Scramble class was somewhat limited. It always produced the words in the same order (the order that they were stored in the file) and each time the words were needed they had to be read from the file. In this assignment your class (called Scramble2 to avoid confusion) will have the following required improvements:
When your Scramble2 object is created, it will read in and store all of the words from the file into an array or ArrayList instance variable. Just like in Assignment 2, you should use the file "words.txt" for your words.
When a getRealWord() / getScrambledWord() call is made, the word returned should be randomly chosen from within the list of words. This process must not return the same word twice and must use all of the words in the list before returning null.
A reset() method must be added which will reinitialize the list. However, this should NOT read the words from the file again. The only time the file should be accessed is when the list is created in the constructor. The reset() method should work even if the words have only been "partially" used (ex: 5 out of a list of 10 words are used and then the reset() method is called).
To test your Scramble2 class, run it with the program NewScramTest.java. It should produce output similar to that of NewScramTest.txt (however, since the words are produced
1 of 3 10/2/19, 3:52 PM
https://web.archive.org/web/20180419174109/http://people.cs.pi...
MAR
APR
MAY
⍰
Go
22 captures
19
f d
2016
2018
2019
31 Oct 2014 - 21 Mar 2019
▾ About this capture
individually through two new classes: the Player class and (described
the PlayerList class.
A Player object will be an encapsulation of the player's name, win / loss information and methods for accessing and mutating the player information.
While a player is playing the game, his / her information should be accessed through a Player object, and that object should be updated after each round to reflect the result of that round.
There are several ways of implementing your Player class, but some minimal requirements are shown in the test program PlayerListTest.java. Your Player class (and PlayerList class) must work with this program and the output must be consistent with that shown in the file PlayerTest.txt. Note, however, that this test program may not test everything that you will need in your Player class.
PlayerList class: To organize / maintain your Player objects, you must also implement a PlayerList class. This is a simple "database" class similar to the one from Lab 7. This class should allow the Player objects to be read in from a text file (use the file "players.txt") and then to be accessed as needed during your game.
The "players.txt" file will be formatted with the information for one player on each line of the file, as shown below
<name <rounds <won <lost
where <name is the name of the player, <rounds is the total number of rounds played by the player, <won is the total number of rounds won by the player and <lost is the total number of rounds lost by the player. There is a single blank space between each item on each line. The file can have an indefinite number of lines in it.
At the end of the game all of the Player objects should be saved back to the file so that the information is updated if the program is run again.
Some of the required functionality of your PlayerList class is shown in the program PlayerListTest.java. Your PlayerList class must run with this program as given and the output should be consistent with that provided in PlayerTest.txt. Note, however, that this test program may not test everything that you will need in your PlayerList class.
Assig3 class (main program): Playing a single "game" will be the same as it was in Assignment 2 (see Assignment 2 for details). However, your Assig3 program will be enhanced in the following ways:
Now you will have an extra, outer loop, which will allow multiple players to play the game, one at a time. For each "game" you will ask the player to enter his / her name. If he / she is already registered you should then retrieve the correct Player object from the PlayerList and use that during the playing of the game. However, if the player is not registered you should create a new Player object and add it to the PlayerList.
At the end of each game you should show to the player the results from that "game" (i.e. rounds, wins and losses in the current session) followed by the overall results (from all sessions together) for that Player (by using the toString() method from the Player object).
Once all players are done playing the game you should show the cumulative statistics, as provided by the toString() method of the PlayerList object.
Since you are now keeping the individual results in the Player objects and the overall stats in the PlayerList object, you will no longer need the Results class in this program.
Since your Scramble2 class has a reset() method, you should reset() it before each Player plays the game. You should NOT make a new Scramble2 object for each Player.
For an example of how the program output may look, see a3out.txt. Note that your output does not have to match this exactly, but it should be well-formatted and have the same
2 of 3 10/2/19, 3:52 PM
https://web.archive.org/web/20180419174109/http://people.cs.pi...
MAR
APR
MAY
⍰
Go
22 captures
19
f
Is
2016
2018
2019
31 Oct 2014 - 21 Mar 2019
▾ About this capture
You will need to use files in several places in this program. In particular you will need to read the words from "words.txt" into your Scramble2 object and you will need to read the players into the PlayerList object from "players.txt". Note that in both cases you should read from the file only one time for the entire program execution.
The words.txt and players.txt files will be provided for you. Note, however, that these files could be changed and/or different versions of them could be used to test your programs. Your program should work for any properly formatted "words.txt" and "players.txt" files.
Test your program thoroughly before handing it in. Make sure it functions as required in all cases. I have generated some sample output that may help you with this. See: a3out.txt.
Don't forget your Assignment Information Sheet -- you will lose points without it.
Don't forget to comment your code - you will lose points without them.
Note that you must have 9 files in your .zip submission file for this assignment:
Assig3.java
Scramble2.java
Player.java
PlayerList.java
NewScramTest.java
PlayerListTest.java
words.txt
players.txt
Your assignment information sheet
The first 4 files you must write yourself and the next 4 files you should pass on unaltered from how they are provided for you on the web site. Make sure all of these files are present or you will lose submission points!
Extra Credit Options
The Player in this game is identified by an id, but no password is required. Add a password field for each Player and require the Player to enter the correct password before playing the game. Note that this will also require changes to the format of your players.txt file.
Write an administrator program that allows an administrator to log in (using an id and password) and to see / update the players (change a score for a player, add a player, remove a player, etc). This should utilize the Player.java and PlayerList.java classes.
3 of 3 10/2/19, 3:52 PM