Results 1 to 18 of 18
- 07-24-2010, 07:30 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 12
- Rep Power
- 0
-
This is a forum not a seance. Without your code I'm afraid we can't help you.
- 07-24-2010, 07:48 PM #3
Member
- Join Date
- Jul 2010
- Posts
- 12
- Rep Power
- 0
http://aswiftlytiltingplanet.net/driver.java
http://aswiftlytiltingplanet.net/PaperRockScissors.java
I fixed the main problem (the object is now created for each round), but now I just need to fix the output of the wins and losses. I would like them to increase gradually, not what it's doing (sporadically changing).
- 07-24-2010, 07:49 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
You're doing all the work (i.e. play all the games) in your constructor but you're not printing any results in that constructor. The while loop in your main method simply prints out the same results over and over again.
kind regards,
Jos
ps. better post your code (or a relevant fragment thereof) in this forum. Not everybody is willing to download and open unknown files)
- 07-24-2010, 07:53 PM #5
Member
- Join Date
- Jul 2010
- Posts
- 12
- Rep Power
- 0
I fixed the problem.
Last edited by JavaStudent1990; 07-24-2010 at 09:04 PM. Reason: Code tags added
- 07-24-2010, 07:53 PM #6
Member
- Join Date
- Jul 2010
- Posts
- 12
- Rep Power
- 0
I fixed the problem.
Last edited by JavaStudent1990; 07-24-2010 at 09:03 PM. Reason: Code tags added
- 07-24-2010, 08:00 PM #7
Member
- Join Date
- Jul 2010
- Posts
- 12
- Rep Power
- 0
Also, I'm studying for a test, and the driver has to be the one that prints the messages--not the constructor.
"For each hand your Driver will print a message saying what the computer picked, what the user picked and who won the hand. It will then print the score: Human: 1 Computer 0
Human: 1 Computer 1"
- 07-24-2010, 08:01 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Reread my previous reply (reply #4) and manually check how your main( ... ) method gets those numbers again and again (hint: nothing happens that could change them). You would've gotten similar constant values in C++.
kind regards,
Jos
-
java student: I hope you don't mind that I edited your posts and added code tags to help make your code readable. To learn how to do this yourself, please click on the related link in my signature.
Much luck!
- 07-24-2010, 08:29 PM #10
Member
- Join Date
- Jul 2010
- Posts
- 12
- Rep Power
- 0
I fixed the problem.
Thank you all for the suggestions.Last edited by JavaStudent1990; 07-24-2010 at 09:04 PM.
- 07-24-2010, 08:35 PM #11
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
If this is the body of your loop in the main( ... ) method:
... no numbers are changing because nothing happens in those few methods you are calling from that loop body. Check it.Java Code:PaperRockScissors game; game = new PaperRockScissors(inGames); System.out.println("You " + game.getResult( ) + ".\nThe user wielded " + game.getUserChoice( ) + " and the computer wielded " + game.getComputerChoice( ) + "."); System.out.println("Score\nHuman: " + game.getWins( ) + " Computer: " + game.getLosses( ));
kind regards,
Jos
- 07-24-2010, 08:41 PM #12
-
To the original poster, please do not cross-post without notifying us that you are doing this.
The problem is that you're asking unpaid volunteers to help you here, not paid consultants, and most of us mind if we take time away from work/lives/play to try to help someone only to find that we've provided a solution that was already provided in a cross-post hours ago. The proper thing to do is that if you feel you must cross-post, at least provide links in each cross-post to the other, so that folks don't waste time answering something already answered and so that folks can review all discussions that have already occurred.
Thank you for your cooperation.
-
The OP has deleted his questions and code which is also not a good thing, as this forum is not about just answering his question but also about folks in the future with similar problems looking at this thread and using the solutions suggested to help solve their problems.
For what it's worth, here is some of his original code:
Java Code:import java.util.*; /** * Write a description of class PaperRockScissors here. * * @author (your name) * @version (a version number or a date) */ public class PaperRockScissors { // instance variables - replace the example below with your own private int userRandomNumber; private int computerRandomNumber; private int numberOfGames; private int restart = 1; private int winCounter = 0; private int lossesCounter = 0; String result; String userChoice; String computerChoice; Random randomChoice = new Random(); public PaperRockScissors( ) { userRandomNumber = -1; computerRandomNumber = -1; numberOfGames = 0; restart = 0; winCounter = 0; lossesCounter = 0; } public PaperRockScissors(int inGames) { numberOfGames = inGames; while (numberOfGames > 0) { userRandomNumber = randomChoice.nextInt(3); computerRandomNumber = randomChoice.nextInt(3); if(userRandomNumber == 0 && computerRandomNumber == 0) { userChoice = "paper"; computerChoice = "paper"; result = "have a draw"; } else if(userRandomNumber == 0 & computerRandomNumber == 1) { userChoice = "paper"; computerChoice = "rock"; result = "won"; winCounter++; } else if(userRandomNumber == 0 && computerRandomNumber == 2) { userChoice = "paper"; computerChoice = "scissors"; result = "lost"; lossesCounter++; } else if(userRandomNumber == 1 && computerRandomNumber == 0) { userChoice = "rock"; computerChoice = "paper"; result = "lost"; lossesCounter++; } else if(userRandomNumber == 1 & computerRandomNumber == 1) { userChoice = "rock"; computerChoice = "rock"; result = "have a draw"; } else if(userRandomNumber == 1 && computerRandomNumber == 2) { userChoice = "rock"; computerChoice = "scissors"; result = "won"; winCounter++; } else if(userRandomNumber == 2 && computerRandomNumber == 0) { userChoice = "scissors"; computerChoice = "paper"; result = "won"; winCounter++; } else if(userRandomNumber == 2 & computerRandomNumber == 1) { userChoice = "scissors"; computerChoice = "rock"; result = "lost"; lossesCounter++; } else if(userRandomNumber == 2 && computerRandomNumber == 2) { userChoice = "scissors"; computerChoice = "scissors"; result = "have a draw"; } numberOfGames--; } } public String getUserChoice( ) { return userChoice; } public String getComputerChoice( ) { return computerChoice; } public String getResult( ) { return result; } public int getWins( ) { return winCounter; } public int getLosses( ) { return lossesCounter; } }
- 07-25-2010, 05:46 PM #15
Member
- Join Date
- Jul 2010
- Posts
- 12
- Rep Power
- 0
I would prefer that my code not be re-posted, as it is not something my school would want online out of respect for the class. Future students might just copy and paste the code rather than figure it out and ask their own questions in order to learn. Thus my original hesitation to post it in text. That would be why I deleted the code. I needed advice, and you all asked for what I was working on, so I complied. I just would wish that the code not be re-posted.
- 07-25-2010, 05:52 PM #16
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
-
We like to retain code here for several reasons. One as Jos points out and as I mentioned, for the benefit of future coders with similar questions, and two, for the benefit of the schools as your instructors will need to know that you have asked this question here and have received whatever help you have received. As a past instructor, believe me, I know that they will want to know this. So for these reasons and others, the code should stay.
- 07-25-2010, 07:20 PM #18
Member
- Join Date
- Jul 2010
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
generate pseudo random numbers in java
By csr81 in forum Advanced JavaReplies: 3Last Post: 03-01-2010, 07:08 AM -
hard question .. help me .. about creating random numbers
By soldier in forum New To JavaReplies: 5Last Post: 12-21-2009, 01:17 PM -
How do I generate random numbers in a certain range using the random class?
By frasifrasi in forum New To JavaReplies: 8Last Post: 04-19-2009, 05:50 PM -
RTP question about random numbers
By tornbacchus in forum New To JavaReplies: 4Last Post: 04-14-2009, 03:58 AM -
random numbers without using java funtions
By carlos123 in forum New To JavaReplies: 8Last Post: 11-16-2007, 10:13 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks