Problem fixed, thank you all for the suggestions.
Printable View
Problem fixed, thank you all for the suggestions.
This is a forum not a seance. Without your code I'm afraid we can't help you.
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).
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)
I fixed the problem.
I fixed the problem.
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"
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!
I fixed the problem.
Thank you all for the suggestions.
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.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
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:
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;
}
}
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.
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.
I'm a girl, so it would be her code. =P
In that case, I might as well post the working code once I don't feel like I'd be violating an honor code, giving out my code. I got everything working properly.