Results 1 to 4 of 4

Thread: Curious

  1. #1
    Cutter is offline Member
    Join Date
    Aug 2009
    Posts
    11
    Rep Power
    0

    Default 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:

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    11

    Default

    JOptionPane.showInputDialog return String, and randNumOne is int, they cant compare,
    you should use
    Java Code:
     new Integer(userInputThree).intValue() == randNumXX
    and in your second if statement, || && placed in same level, you should use () correctly to separate them

  3. #3
    Cutter is offline Member
    Join Date
    Aug 2009
    Posts
    11
    Rep Power
    0

    Default 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

    Java Code:
    new Integer(userInputThree).intValue() == randNumXX
    and where it would fit

    Please elaborate :confused::)

  4. #4
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    11

Similar Threads

  1. curious about iterator
    By jacline in forum New To Java
    Replies: 1
    Last Post: 03-16-2009, 04:29 AM
  2. A Curious Programming Hobbyist :)
    By Jesdisciple in forum Introductions
    Replies: 4
    Last Post: 05-11-2008, 10:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •