Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 24th, 2005, 07:12 PM
mundj mundj is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 1 mundj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 40 sec
Reputation Power: 0
Angry I need help with my rock paper scissors program

Here is my code:

import java.util.Scanner;
import java.util.Random;
public class RockPaperScissors
{
public static final int ROCK = 1;
public static final int PAPER = 2;
public static final int SCISSORS = 3;
//
// Plays Rock-Paper-Scissors game with the user
//
public static void main(String[] args)
{
final int NUM_CHOICES = 3;
Random generator = new Random();
int userWins = 0;
int compWins = 0;
int ties = 0;
int compOption, userOption;
boolean exit = false;
Random randGen = new Random();
Scanner scan = new Scanner(System.in);
System.out.println("The Rock-Paper-Scissors Game");
System.out.println("Enter your choice: ");
userOption = scan.nextInt();

System.out.println("Computers Choice: ");
compOption = scan.nextInt();



//Prompt game results
System.out.println("-------------------------------------------");
System.out.println("Game Results");
System.out.println("User won: " + userWins + " times");
System.out.println("Computer won: " + compWins + " times");
System.out.println("User and Computer Tied: " + ties + " times");
System.out.println("-------------------------------------------");
} // method main
//
// Method displays options to user.
//
public static void promptOptions()
{
System.out.println("-------------------------------------------");
System.out.println("1. Rock");
System.out.println("2. Paper");
System.out.println("3. Scissors");
System.out.println("4. Exit");
System.out.print("Enter Option: ");
} // method promptOptions
}


i am having trouble with how to set up the rock, paper and scissor so that it can be played. i am also not sure how to set up my "if" statement. it has me a little confused so if i could get some hints that would be awesome!

Reply With Quote
  #2  
Old February 26th, 2005, 05:04 AM
gertcuppens's Avatar
gertcuppens gertcuppens is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 118 gertcuppens User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 28 m
Reputation Power: 5
I don't know the exact rules of the game, so I'll leave
that part to you. But what I would do is write a second
class, for example RockGame. This class would accept
the choice of the user, the choice of the computer and
keep the score. So, you'll need some properties, getters
and setters. You could even let the class RockGame produce
a random choice of the computer.

You should add a while loop to play the game. As long as the
user doesn't enter a certain key, he/she will keep on playing.
Inside the while loop, you can use the second class RockGame
or whatever you want to call it. The user enters his/her choice,
and RockGame produces the random choice of the computer,
decides who won and notes this in the score.

As soon as the user enters the key to stop the game, RockGame
outputs the final score.
The advantage of using a second class is that you're getting a
feeling of how to work with classes and objects. The way you are
writing it now, is more the procedural way. I don't mean it's bad
but Java is conceived to let you build classes and reuse them.
ANd with RockGame you could give this way of programming a try.

Reply With Quote
  #3  
Old February 28th, 2005, 09:35 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
What happens when the code you have is run?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > I need help with my rock paper scissors program


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT