Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link

Noland Oakley

Greenhorn
+ Follow
since Apr 03, 2007
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Noland Oakley

Hello, I have a project in which it is supposed to take the following contents of a text file:



and remove the duplicates and then create a new file with the same contents minus the duplicates. Here is my code:



It seems like it should work but it doesn't. When run the final file contains this:



What is wrong with my code? Thanks!

P.S. To make the purpose of this program clearer, here is a copy of the assignment:


Remove the Duplicates



Create a new project named Duplicates in a workspace folder. Add the template files and rename the template LNFI_Duplicates.

You may work with a partner on this project, but you may not work in larger groups. If you work with a partner, simply add both names as a comment to the top of the Duplicates class. You only need to hand in one copy. There is no collaboration (other than minor help) with anyone other than your partner.

Located in the shortcut folder is a text document named �puzzles.txt�. This file contains phrases that could be used for Wheel of Fortune or some similar game. The only problem is that it contains some phrases that are duplicates. For example, the phrase �Mickey Mouse� appears on the list two or more times.

You are to write a program that reads puzzles.txt and writes a second text file named puzzles2.out that is identical to puzzles.txt except there are no duplicate puzzles. Capitalization does not matter. Therefore, �Mickey Mouse� and �mickey mouse� are duplicates.

I would suggest reading each puzzle from the input file into an ArrayList and then going through the array list one puzzle at a time and removing the duplicates. This is a fairly easy assignment using an ArrayList, but it would be fairly difficult if you use an array. There may be an easier way to do it other than using an ArrayList, but I don�t know what it would be. If you think of an easier way, you may do it that way.



JCE: broke up some long lines
[ September 06, 2007: Message edited by: Joe Ess ]
14 years ago
ok, so I have a project I'm working on, here's its description:

Create a new project named FML_Pig where F is your first initial, M is your middle initial, and L is your last initial. For example, if your name is Alfred Edward Neuman then you would name your project AEN_Pig. If necessary, add a new Java file to this project named FML_Pig.



Add a java file to the project named FML_Dice.



Design and implement a Dice class as follows. The Dice class has 2 twenty‑sided dice with numbers on the faces (1 � 20) and 2 twenty-six-sided dice with letters on the faces (a � z).











Part 1



Add a rollDice() method to your FML_Dice class that sets die1 and die2 to a random number between 1 and 20 and it sets die3 and die4 to a random character between �a� and �z�.



Helpful Hint:















Part 2



Write a constructor that sets die1 and die2 to a random number between 1 and 20 and it sets die3 and die4 to a random character. Your constructor can simply call rollDice() to do this. It should also initialize numSnakeEyes, numVowels, and totalPoints to 0 (after you roll the dice).



Part 3



Write methods getDie1(), getDie2(), getDie3(), and getDie4() that returns the value of the respective die. Write a method numSnakes() that returns the number of snake eyes that have been rolled. Write a method numVowels() that returns the number of vowels that have been rolled. Write a method totalPts() that returns the totalPoints.





Part 4



Write a toString() method that overwrites the default toString() method. It should return a String representation of the value of all 4 die. For example, 17 2 h w.



Part 5



Write a method updateTotals that updates numVowels, numSnakeEyes, and totalPoints based on the current values of die1, die2, die3, and die4. numVowels should be incremented by 1 if either die3 or die4 are a vowel. However, if both die3 and die4 are vowels, the totalPoints should be reset to 0 and numVowels should be reset to 0 also. numSnakeEyes should be incremented by 1 if either die1 or die2 have a face value of 1 (this is not truly a snake eyes, but it gives better odds for the game). totalPoints should be incremented by the sum of die1 and die2 multiplied by (numSnakeEyes + 1).



Part 6



Write a main program (use the one in FML_Pig.java) that plays a game of Pig. In this game, two people play against each other. Player1 begins by rolling the dice. The total of die1 and die2 is added to his total score. Player1�s turn continues until he/she rolls a total of 4 vowels then the turn switches to Player2. Whenever a turn switches to the other player, the number of vowels is reset to zero. Also, if at any time both die3 and die4 are vowels, the total score is reset to 0 and the turn switches to the other player. (So the turn switches to the other player whenever the total number of vowels reaches four or there are two vowels rolled at the same time.)



If a player rolls snakeeyes (for our game, snakeeyes occurs whenever either of the dice have a face value of one � in reality, both die1 and die2 should have a face value of one but then snakeeyes would occur only once every 400 rolls), then his point values are doubled from that point on (all future rolls for the rest of the game, point values for this player are doubled). When a player rolls snake eyes again, point values are tripled for that roll and all future rolls. (Three snake eyes, quadrupled, etc.)



(continued on the next page)

Be sure to display the results of the roll for each turn.



First player to get to 2000 points wins the game and gets to oink like a pig.

Note: Both players need their own set of Dice since the Dice keeps track of the totalPoints, the number of snake eyes rolled so far, and the number of vowels rolled so far for that particular player. You can do this simply by declaring it that way in the main program:







You may add additional methods and instance variables to the class as needed. For example, I would probably write a private helper method isVowel() that is passed a char argument ch and returns true if ch is a vowel.



Also, you can have the computer play for both player 1 and player 2. Simply loop it until somebody wins. Print out the result for each turn including who rolled the dice (player 1 or player 2), what they rolled, how many snakeeyes do they have, how many points did they get for this turn, and how many total points do they have.



When you are completely finished, hand in just the java files (FLM_Dice & FLM_Pig). If you happened to write any other classes, make sure they are named with the FML format, and turn these in as well. I do not need EasyReader or p.


Oink! Oink!







This pig won the game --------->



so here's my code:

this isn't my code but is required to compile my code:





same with this:





here's my code:






and dice class:





the program works fine except it's supposed to terminate when one of the two AIs get a score of 2000, right now it terminates no matter what score the AIs get and no matter what I've tried to do it keeps doing that...can someone please tell me why it's terminating so oddly? Thanks!
15 years ago