Results 1 to 4 of 4
Thread: Curious
- 09-12-2009, 02:29 AM #1
Member
- Join Date
- Aug 2009
- Posts
- 11
- Rep Power
- 0
Curious
Hey all...
taking an online course for personal not school related reasons
Having said that...my level is still low, so can someone give me a push in the right direction..
this is what I need;
create an lottery
have user input 3 numbers
compare numbers against 3 random numbers
1 match win $10
2 match win $100
3 match (not in order) win $1000
3 match in order win $100000
cannot win twice...ie...win the $1000 and the $100, $10 at the same time.
This is where I am.
Java Code:import java.util.*; import javax.swing.JOptionPane; public class RockPaperScissors { public static void main (String[] args) { Random randOne = new Random(); int randNumOne = randOne.nextInt(10); System.out.println(randNumOne); Random randTwo = new Random(); int randNumTwo = randTwo.nextInt(10); System.out.println(randNumTwo); Random randThree = new Random(); int randNumThree = randThree.nextInt(10); System.out.println(randNumThree); String guessStringOne; int userInputOne; guessStringOne = JOptionPane.showInputDialog(null, "Please enter 3 digits from 0-9 \nEnter your first number", "Lottery Numbers", JOptionPane.QUESTION_MESSAGE); userInputOne = Integer.parseInt(guessStringOne); String guessStringTwo; int userInputTwo; guessStringTwo = JOptionPane.showInputDialog(null, "Enter your second number", "Lottery Numbers", JOptionPane.QUESTION_MESSAGE); userInputTwo = Integer.parseInt(guessStringTwo); String guessStringThree; int userInputThree; guessStringThree = JOptionPane.showInputDialog(null, "Enter your third number", "Lottery Numbers", JOptionPane.QUESTION_MESSAGE); userInputThree = Integer.parseInt(guessStringThree); if (randNumOne == userInputOne && randNumTwo == userInputTwo && randNumThree == userInputThree) System.out.println("A:Exact match:You win $1,000,000"); else if (randNumThree == userInputThree && randNumTwo == userInputTwo && randNumOne == userInputOne || randNumThree == userInputTwo && randNumThree == userInputOne || randNumTwo == userInputThree && randNumTwo == userInputOne || randNumOne == userInputThree && randNumOne == userInputTwo) System.out.println("B:Matched two Numbers:You win $1000"); else if (randNumOne == userInputOne) System.out.println("D:Matched one Number:You win $10"); else if (randNumOne == userInputTwo) System.out.println("E:Matched one Number:You win $10"); else if (randNumOne == userInputThree) System.out.println("F:Matched one Number:You win $10"); else if (randNumTwo == userInputOne) System.out.println("G:Matched one Number:You win $10"); else if (randNumTwo == userInputTwo) System.out.println("H:Matched one Number:You win $10"); else if (randNumTwo == userInputThree) System.out.println("IMatched one Number:You win $10"); else if (randNumThree == userInputOne) System.out.println("J:Matched one Number:You win $10"); else if (randNumThree == userInputTwo) System.out.println("k:Matched one Number:You win $10"); else if (randNumThree == userInputThree) System.out.println("L:Matched one Number:You win $10");
I know its the long way around, but it matches my skill lvl at the moment.
now Im stuck....:confused:
- 09-12-2009, 03:13 AM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
JOptionPane.showInputDialog return String, and randNumOne is int, they cant compare,
you should use
and in your second if statement, || && placed in same level, you should use () correctly to separate themJava Code:new Integer(userInputThree).intValue() == randNumXX
- 09-12-2009, 01:04 PM #3
Member
- Join Date
- Aug 2009
- Posts
- 11
- Rep Power
- 0
Thank you
Hi mtyoung,
I cleaned it up a bit and added the () where they should be as you have indicated.
Java Code:import java.util.*; import javax.swing.JOptionPane; public class Lottery { public static void main (String[] args) { Random randOne = new Random(); int randNumOne = randOne.nextInt(10); System.out.println(randNumOne); Random randTwo = new Random(); int randNumTwo = randTwo.nextInt(10); System.out.println(randNumTwo); Random randThree = new Random(); int randNumThree = randThree.nextInt(10); System.out.println(randNumThree); String guessStringOne; int userInputOne; guessStringOne = JOptionPane.showInputDialog(null, "Please enter 3 digits from 0-9 \nEnter your first number", "Lottery Numbers", JOptionPane.QUESTION_MESSAGE); userInputOne = Integer.parseInt(guessStringOne); String guessStringTwo; int userInputTwo; guessStringTwo = JOptionPane.showInputDialog(null, "Enter your second number", "Lottery Numbers", JOptionPane.QUESTION_MESSAGE); userInputTwo = Integer.parseInt(guessStringTwo); String guessStringThree; int userInputThree; guessStringThree = JOptionPane.showInputDialog(null, "Enter your third number", "Lottery Numbers", JOptionPane.QUESTION_MESSAGE); userInputThree = Integer.parseInt(guessStringThree); if (randNumOne == userInputOne && randNumTwo == userInputTwo && randNumThree == userInputThree) System.out.println("A:Exact match:You win $1,000,000"); else if ((randNumOne == userInputThree && randNumTwo == userInputTwo && randNumThree == userInputOne) || (randNumOne == userInputTwo && randNumTwo == userInputOne && randNumThree == userInputThree) || (randNumOne == userInputThree && randNumTwo == userInputOne && randNumThree == userInputTwo) || (randNumOne == userInputTwo && randNumTwo == userInputThree && randNumThree == userInputOne) || (randNumOne == userInputOne && randNumTwo == userInputThree && randNumThree == userInputTwo)) System.out.println("B:Matched three Numbers:You win $1000"); else if ((randNumOne == userInputOne && randNumTwo == userInputTwo) || (randNumOne == userInputOne && randNumTwo == userInputThree) || (randNumOne == userInputThree && randNumTwo == userInputOne) || (randNumOne == userInputTwo && randNumTwo == userInputOne) || (randNumOne == userInputTwo && randNumTwo == userInputThree) || (randNumOne == userInputThree && randNumTwo == userInputTwo) || (randNumTwo == userInputOne && randNumThree == userInputTwo) || (randNumTwo == userInputOne && randNumThree == userInputThree) || (randNumTwo == userInputThree && randNumThree == userInputOne) || (randNumTwo == userInputTwo && randNumThree == userInputOne) || (randNumTwo == userInputTwo && randNumThree == userInputThree) || (randNumTwo == userInputThree && randNumThree == userInputTwo) || (randNumOne == userInputOne && randNumThree == userInputTwo) || (randNumOne == userInputOne && randNumThree == userInputThree) || (randNumOne == userInputThree && randNumThree == userInputOne) || (randNumOne == userInputTwo && randNumThree == userInputOne) || (randNumOne == userInputTwo && randNumThree == userInputThree) || (randNumOne == userInputThree && randNumThree == userInputTwo)) System.out.println("C:Matched Two Numbers:You win $100"); else if (randNumOne == userInputOne) System.out.println("D:Matched one Number:You win $10"); else if (randNumOne == userInputTwo) System.out.println("E:Matched one Number:You win $10"); else if (randNumOne == userInputThree) System.out.println("F:Matched one Number:You win $10"); else if (randNumTwo == userInputOne) System.out.println("G:Matched one Number:You win $10"); else if (randNumTwo == userInputTwo) System.out.println("H:Matched one Number:You win $10"); else if (randNumTwo == userInputThree) System.out.println("I:Matched one Number:You win $10"); else if (randNumThree == userInputOne) System.out.println("J:Matched one Number:You win $10"); else if (randNumThree == userInputTwo) System.out.println("k:Matched one Number:You win $10"); else if (randNumThree == userInputThree) System.out.println("L:Matched one Number:You win $10"); else System.out.println("SORRY NO MATCH"); } }
It seems to work now, but I wasn't 100% sure what you meant by
and where it would fitJava Code:new Integer(userInputThree).intValue() == randNumXX
Please elaborate :confused::)
- 09-14-2009, 06:25 AM #4
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
sorry, i misread something...
Similar Threads
-
curious about iterator
By jacline in forum New To JavaReplies: 1Last Post: 03-16-2009, 04:29 AM -
A Curious Programming Hobbyist :)
By Jesdisciple in forum IntroductionsReplies: 4Last Post: 05-11-2008, 10:31 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks