thejestergl
Jan 30 2008, 05:37 PM
I am currently taking a simple Java course and I made a program that allows you to play the simple game of Rock, Paper, Scissors. I have tested and it seems to work but others seem to have trouble with the program and say there are some bugs. I would really appreciate the help! Thank you in advance. CODE import java.awt.*; import java.awt.event.*; import javax.swing.*;
public class Rps extends JFrame implements ActionListener { private final char moves[] = {'R', 'P', 'S'}; private JRadioButton rock, paper, scissors; private JTextField display;
public Rps() { super("Rock, paper, Scissors");
rock = new JRadioButton(" Rock ", true); paper = new JRadioButton(" Paper "); scissors = new JRadioButton(" Scissors ");
ButtonGroup rpsButtons = new ButtonGroup(); rpsButtons.add(rock); rpsButtons.add(paper); rpsButtons.add(scissors);
JButton go = new JButton(" Go "); go.addActionListener(this);
display = new JTextField(25); display.setEditable(false); display.setBackground(Color.yellow);
Container c = getContentPane(); c.setLayout(new FlowLayout()); c.add(rock); c.add(paper); c.add(scissors); c.add(go); c.add(display); }
/** * returns -1 if the player wins, * 0 if it's a tie, and 1 if the computer wins */ private int nextPlay(char computerMove, char playerMove) { int result = 0; switch(computerMove) { case 'R': switch (playerMove) { case 'R': result = 0; break; case 'P': result = -1; break; case 'S': result = 1; break; } break; case 'P': switch (playerMove) { case 'R': result = 1; break; case 'P': result = 0; break; case 'S': result = -1; break; } break; case 'S': switch (playerMove) { case 'R': result = -1; break; case 'P': result = 1; break; case 'S': result = 0; break; } break; } return result; }
public void actionPerformed(ActionEvent e) { char playerMove, computerMove; if (rock.isSelected()) playerMove = 'R'; else if (paper.isSelected()) playerMove = 'P'; else // if (scissors.isSelected()) playerMove = 'S';
int k = (int)(Math.random() * 3); computerMove = moves[k]; int result = nextPlay(computerMove, playerMove);
String msg = " You said " + makeWord(playerMove) + ", I said " + makeWord(computerMove); if (result < 0) msg += " -- you win."; else if (result == 0) msg += " -- tie."; else // if (result > 0) msg += " -- I win."; display.setText(msg); }
private String makeWord(char move) { String word = "";
switch (move) { case 'R': word = "ROCK"; break; case 'P': word = "PAPER"; break; case 'S': word = "SCISSORS"; break; } return word; }
public static void main(String[] args) { Rps window = new Rps(); window.setBounds(300, 300, 300, 140); window.setDefaultCloseOperation(EXIT_ON_CLOSE); window.setVisible(true); } }
Reply
salamangkero
Jan 31 2008, 05:20 AM
What are the bugs other people are finding? I tried your code and it works fine, only there were warning during compilation: warning: [serial] serializable class Rps has no definition of serialVersionUID public class Rps extends JFrame ^ 1 warningwhich, I've read, can be fixed by adding any static, final and long field named "serialVersionUID" in your class: <ANY-ACCESS-MODIFIER> static final long serialVersionUID = 42L;Basically, that's all the "problem" I ever encountered; is this it or was there, altogether, something else?
Reply
thejestergl
Jan 31 2008, 03:59 PM
Ah, no I actually talked to those people and they said that they actually changed some stuff around that they THOUGHT were errors. Some also said that when the played the game itself it kind of messed up, or didn't seem right. But then again they are more of a perfectionist than I am haha. Thank you for your input
Reply
Similar Topics
Keywords : rock, paper, scissors, bugs,
- Unix Has Bad Bugs
Ubuntu (4)
I Hate Rap (mostly As A Whole) And I Love Rock (again Not All Of It)
Why? (10) You know what I really like. I like rocking out with my *explicit* out! Pardon my french.
I'm serious, I love every type of music. Well, almost every time. I hate Rap. Well, not exactly
rap as a whole, but I hate it. To a lesser degree. I dislike Rap because of the rappers who go about
disrespecting women with their lyrics, like if they go around saying, I be with your mama on the
parking lot while she's feasting on my lollypop, ya dig? What the hell is that supposed to
represent? They try to force their bad stereotypes on the black community. With incites....
White Paper: Security Threat Report: 2008
(0) I saw this white paper and I thought I bring down some interesting information that has come from
2007 and leading into 2008. I have to say though that the information on this white paper is pretty
darn mind blowing as I bounce some facts to everyone. Of course since I been getting into this
since last year it is not all that surprising since I posted many topics about it as well.
-Sophos currently sees 6,000 new infected webpages each day -One infected page every 14 seconds
-Only about 1 in 5 of these sites is a hacker site -83 percent are hacked sites, or legitima....
Marijuana
A paper I wrote for english class (3) I wrote an essay similar to this for my English class, I was wondering what some people thought
about it or maybe some nice people can point out some typos and etc since i have no one to proof
read to me. QUOTE Since the 1930s the DEA has been monitoring and illegalizing the use of
drugs. Out of these “drugs” many of them have beneficial purposes in various medical
fields while others were used for religious purposes as well. The Drug Enforcement Agency of the
United States has been strict and manipulative in order to keep these substances illegal. One o....
Why Do People Hate Australias Because Of Spiders?
It really bugs me when people say they hate Australia just because of (5) Hello all, I feel like having a rant about this, it is bugging me /dry.gif"
style="vertical-align:middle" emoid=" Why do people constantly get scarred away from Australia by
1) the heat and 2) spiders ? It makes no sense at all. To be honest, I would have thought that
South America is worse than here- they actually have Tarantulas and other large horrible spiders
over there. /mad.gif" style="vertical-align:middle" emoid=":angry:" border="0" alt="mad.gif" />
It just bugs me. I was chatting to a person on MSN today, and they were obviously completely
uneducated a....
Beryl/compiz Bugs
(3) Just a minute ago I was ready to throw my computer across the room because Beryl was bugging out on
me. Linux users will know that this outstanding window decorator and "eye candy engine" is and will
still be for some time to come in a beta stage, which means that it will have its fair share of
bugs. There are two bugs that completelly ruin my Kubuntu experience: 1.) When drawing a window,
sometimes just the title bar appears and the rest of the window is completely black unless you
resize it or have it redrawn in any sort of way. This means that I can't see ANYTHI....
From Paper To Film
Do TV series and movies affect an author's literary works? (1) I've been wondering, for the past month, how much of the Harry Potter series is actually JK
Rowling's idea, that is, pure, unadulterated ideas. Er... lemme elaborate. Before the last
books came out, there already are film adaptations of the first few books. Sometimes, I wonder,
would Rowling have made the story run a different course had someone other than Daniel Radcliffe,
Rupert Grint or Emma Watson been casted? Would her last two books, The Half-Blood Prince and The
Deathly Hallows have been significantly different if the special effects of the first movie we....
Amazing Origami Photos - Art Of Paper Folding
this is amazing! (15) ....
What Pests Do You Have?
Ringworm, maggots, mice, or bed bugs? (16) I was just wondering if anyone wants to mention their favorite vermin and how they're getting
on. I've got mites, mostly dust mites, but I'm sure there are others feeding on my rotting
carcass at night as I lay there, mouth half open, drool pooling on the pillow cover. I've had
fleas, ticks, and intestinal worms, but they didn't stick around with the alcohol poisoning.
There are all manner of pests crawling about at any given time. What's your personal favorite?
Anyone here from Worms, Nebraska? Just wondering. Fine place, Worms.......
Rock Band
Rhythm-based co-op game for the PS3 and XBOX 360 (2) Rock Band, released for the Playstation 3 and XBOX 360, is a rhythm-based music simulation game
which requires two to four players to perform karaoke-style guitar/bass/drum/vocal rounds in order
to gain fame and cash. Players can customize their rock star avatars and earn cash for hiring
managers and so forth. Requirement for the game are two guitars, drums, and karaoke microphone.
GameTrailers.com has posted a review for Rock Band in high definition and standard definition
formats: DESIGN: 9.0 GAMEPLAY: 9.2 PRESENTATION: 9.5 OVERALL: 9.3 Standard definition: http://....
'guitar Hero Iii: Legends Of Rock' (some Interesting News)
Videogame review: Latest in the beloved "Guitar Hero" series d (0) When MTV bought Harmonix, developer of the ultrasuccessful "Guitar Hero" vidgames, Activision's
inhouse team Neversoft was left with the unenviable position of taking over a beloved series. Though
there's little that will surprise or amaze those familiar with the franchise, the good news is
that "Guitar Hero III" plays just as well as its predecessors and refines an already well-balanced
formula by giving the game a bit of story and excellent online play. It remains to be seen how it
will stack up against "Rock Band," Harmonix's upcoming game for MTV, but for....
A Symphonic Rock/orchestra Song I Wrote
A Month of Hard Work. (4) I enjoy writing music on my computer. Its definitely a hobby of mine. One of my friends is filming a
short film, and asked me to do the soundtrack for it. I spent a month on this song for his movie,
and i really enjoyed how it came out. This link is to the mp3 file that i created using FL Studio.
http://www.yourfilelink.com/get.php?fid=410546 It will take you to YourFileLink, where you can
download the mp3 if you want. On the page the link takes you too, there will be a link near the
right that says Proceed to File Download Page... sometimes its a little hard to see. ....
Wall Paper
(4) http://img375.imageshack.us/img375/2155/techbgol7.jpg Lol comments please?....
Google Adsense Bugs
AdSense Referral Units are NOT displayed... (4) Hi The Google AdSense Referral Ads are not displayed in my blog last 5 days. The Tech Support Team
says " We Apologize for your inconvenience. Currently we are upgrading our AdSense ... - The total
AdSense Network is under testing... - Please be patient... - Check status updates on Inside AdSense
blog. This is the summary of mail i received today from AdSense Support Team. :)....
Hearts Vector Wall Paper
(2) Well here is my latest Vector wallpaper, for the most part everything is position just about right
but still good either way. Had to download more brushes for this one and also this is a 1024x768
resolution as well enjoy. ....
A Paper On A Book - Tewwg
preview of my paper (0) Their Eyes Were Watching God Essay Question In the novel Their Eyes Were Watching God language is
utilized as a symbolic representation of power. Language is particularly used to represent
superiority and dominance over a specific person or persons. Language is also the primary weapon of
the former slaves because otherwise they have little or no power in the depicted society. These
former slaves use language as a means to prove to each other that they possess power over
individuals. This novels shows that there always is a structured system as to whom has power over
who....
Research Paper Titled: How Have The Negative Effects Of Computers Changed American Society?
looking for comments about this paper (4) This is my research paper for my English class and so I am looking for comments mostly based on the
structure of the essay and the flow of this research paper as well. But you can leave comments about
the overall research paper as well. I am looking for serious comments so anything not related to
this topic will be reported Thank you. Also this Research paper is copyrighted to Michael Anderson
(that me). For reference this is a MLA styled research paper. UPDATES: after a couple of
runthourgh through a couple of instructors and of course peoples comment here on trap ....
Gmail Paper
(4) GMail paper is free service that allows you to request your email from any GMail account to be
printed, and sent to you for free. All Images are printed on glossy photo paper, however WAV and
MP3 files are not sent along. There is no limit to the amount of emails that can be sent. It even
uses 96% post-consumer organic soybean sputum. To read more, go here. Gmail Paper ....
Rock Cakes
quick and easy dried fruit / chocolate / coconut cakes (5) Rock Cakes A quick and easy recipe for some of the world's simplest cakes to cook. The
good thing about them is that they still look impressive. 8oz self-raising flour 4oz castor
sugar 4oz margarine 4oz dried fruit / chocolate cubes / coconut 1 beaten egg Bit of milk
Bowl Spoon Sieve Oven A baking tray either lined with greaseproof paper or greased with
margarine Preheat the oven to 200 o C Sieve the flour into the bowl Rub the margarine in
until the mixture is crumbly like breadcrumbs Mix in every other ingredient until a....
Speech And Research Paper Topic Ideas
(2) In my 10th grade year (this year) we have to do a persuasive speech as well as a research paper on
whatever topics we want, and the persuasive speech has to be on a highly debated topic. So i was
wondering if anyone here could give me any suggestions as to what i would do my speech on. Thanks....
Paper Mario
(5) Anyone heard about this game? I played all of them. If u like adventure then you should get this
game when the third one comes out on the wii.. Comments? /biggrin.gif"
style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" />....
To Save Paper
Without having to eat a beaver (10) I think they should inforce schools to have Laptops for school children. And they could have all
school books on disks, homework sent to school from home. Schoolwork sent to teachers. And parent
control the internet, or only allow so many website suggested by teachers and by students. With no
need for paper we can save these trees everyoen is moaning about saving. Think back to when you was
at school, or if you still are. The amount of paper you use each day. And what do you do with your
school work. You etheir save it at home, or throw it away. Some people burn there wo....
Data Can Be Stored On Paper
Store GB's of electronic data on Paper (31) A student has developed a technique to store data on portable paper :-) ....
Before The Toilet Paper
what did people use? (17) i was wondering--what did people use before the invention of toilet paper because mass producton of
paper is a pretty recent thing and i would think that about 1000 years ago only the wealthy could
afford to use it. Any ideas how this was done in the early days? TY....
Rock, Paper, Scissors
(14) Okay, so I'm trying to figure something out, and part of that is understanding. So In the game
of rock, paper, sicssors what is the best first move, and if possable,why?....
Slow Rock
I want To Know About Love Song (5) Everyone has 1 or more favorite songs. Can you tell me The Song You Like? I want you give me Slow
Rock Song ( Title - the singer) and The Reason why you love it. I want to collect that song and make
My own Audio CD please help me to find the best song you ever hear. Example You're All I Need
- White Lion. Thank's You....
Fave Type Of Music?
Rap, rock, pop, country...? (26) What is your fave type of music? My fave is constantly changing, I was really into pop when I was
still a 'little kid' but I'm really getting into rock now. Anyway, I think that the type
of music someone likes can relate to how people act. If you look at people who really really like
Dance or Pop music they are completely different to people that really really like Rock and heavy
metal stuff. What do you think about that aswell?....
Emotional Rock Song
(5) What do you think is the saddest AND emotional rock song? You can name 1, or 2 if there are 2 songs
that fit into each category. 1.Nothing Else Matters- Metallica for Emotion 2.Rain- Breaking
Benjamin for Sad....
Muse
British rock (11) They are one of my favourite bands. I think they are very original and musical and rock also.....
The best Rock band
(69) here i thought to make a poll but they are too many so we first should post our openions before
making a poll , anyway mine is KORn and linkin park come in the second place. /smile.gif"
style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> note: Mettalica and similar
bands are not considered as they are mital /ph34r.gif" style="vertical-align:middle"
emoid=":ph34r:" border="0" alt="ph34r.gif" />....
Looking for rock, paper, scissors, bugs,
|
|
Searching Video's for rock, paper, scissors, bugs,
|
advertisement
|
|