Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Loopy Lotto....

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Loopy Lotto....

    Cant Seem to get my if thens to stop adding each other. I want them to go num1,num2,num3 but this program is adding all 3 together.... Rough...

    import javax.swing.JOptionPane;
     
    public class Lotto {
    	public static void main(String[] args) {
     
    		String inputOneString = JOptionPane.showInputDialog(
    			"Enter the First Digit of Your Lotto Number Pick");
     
    		int inputOne = 
    			Integer.parseInt(inputOneString);
     
    		String inputTwoString = JOptionPane.showInputDialog(
    			"Enter the Second Digit of Your Lotto Number Pick");
     
    		int inputTwo = 
    			Integer.parseInt(inputTwoString);
     
    		String inputThreeString = JOptionPane.showInputDialog(
    			"Enter the Third Digit of Your Lotto Number Pick");
     
    		int inputThree = 
    			Integer.parseInt(inputThreeString);
     
    		int numberOne = (int)(System.currentTimeMillis() % 10);
    		int numberTwo = (int)(System.currentTimeMillis()*4  % 10);
    		int numberThree = (int)(System.currentTimeMillis()*5 % 10);
    		int lottoNumber = numberOne + numberTwo + numberThree;
    		int userNumber = inputOne + inputTwo + inputThree;
     
    		if (userNumber == lottoNumber) {
    			System.out.println("The Lotto Number Was " + lottoNumber + " Your Numbers Match Exactly!! You Win $10,000");
    		}
    		else if (userNumber == (numberOne + numberThree + numberTwo) OR (numberTwo + numberOne + numberThree) OR (numberTwo + numberThree + numberOne) OR (numberThree + numberOne +numberTwo) OR (numberThree + numberThree + numberOne)){
    			System.out.println("The Lotto Number Was " + lottoNumber + " Your Numbers Match All 3 Numbers in a Different Order!! You Win $3,000");
    		}
    		else if ((inputOne == numberOne) OR (inputTwo == numberTwo) OR (inputThree == numberThree)){
    			System.out.println("The Lotto Number Was " + lottoNumber + " Your Numbers Match 1 of the 3 Numbers!! You Win $1,000");
    		}
    		else {
    			System.out.println("The Lotto Number Was " + lottoNumber + " Your Numbers did not Match any of the Lotto Numbers. You Lose");
    		}
    	}
    }


  2. #2
    Junior Member
    Join Date
    Sep 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Loopy Lotto....

    do i need to put them together in a string and not in a int?

  3. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Cool Re: Loopy Lotto....

    Quote Originally Posted by JavaCow View Post
    Cant Seem to get my if thens to stop adding each other. I want them to go num1,num2,num3 but this program is adding all 3 together.... Rough...

    import javax.swing.JOptionPane;
     
    public class Lotto {
    	public static void main(String[] args) {
     
    		String inputOneString = JOptionPane.showInputDialog(
    			"Enter the First Digit of Your Lotto Number Pick");
     
    		int inputOne = 
    			Integer.parseInt(inputOneString);
     
    		String inputTwoString = JOptionPane.showInputDialog(
    			"Enter the Second Digit of Your Lotto Number Pick");
     
    		int inputTwo = 
    			Integer.parseInt(inputTwoString);
     
    		String inputThreeString = JOptionPane.showInputDialog(
    			"Enter the Third Digit of Your Lotto Number Pick");
     
    		int inputThree = 
    			Integer.parseInt(inputThreeString);
     
    		int numberOne = (int)(System.currentTimeMillis() % 10);
    		int numberTwo = (int)(System.currentTimeMillis()*4  % 10);
    		int numberThree = (int)(System.currentTimeMillis()*5 % 10);
    		int lottoNumber = numberOne + numberTwo + numberThree;
    		int userNumber = inputOne + inputTwo + inputThree;
     
    		if (userNumber == lottoNumber) {
    			System.out.println("The Lotto Number Was " + lottoNumber + " Your Numbers Match Exactly!! You Win $10,000");
    		}
    		else if (userNumber == (numberOne + numberThree + numberTwo) OR (numberTwo + numberOne + numberThree) OR (numberTwo + numberThree + numberOne) OR (numberThree + numberOne +numberTwo) OR (numberThree + numberThree + numberOne)){
    			System.out.println("The Lotto Number Was " + lottoNumber + " Your Numbers Match All 3 Numbers in a Different Order!! You Win $3,000");
    		}
    		else if ((inputOne == numberOne) OR (inputTwo == numberTwo) OR (inputThree == numberThree)){
    			System.out.println("The Lotto Number Was " + lottoNumber + " Your Numbers Match 1 of the 3 Numbers!! You Win $1,000");
    		}
    		else {
    			System.out.println("The Lotto Number Was " + lottoNumber + " Your Numbers did not Match any of the Lotto Numbers. You Lose");
    		}
    	}
    }
    Well, adding integers together will add them mathematically.

    Yes, make it a String.

    String lottoNumber = numberOne + "," + numberTwo + "," + numberThree;

    String userNumber = inputOne + "," + inputTwo + "," + inputThree;

    if (lottoNumber.equals(userNumber))

    Also, perhaps it'll add it

    else if (userNumber == (numberOne + numberThree + numberTwo) OR (numberTwo + numberOne + numberThree) OR (numberTwo + numberThree + numberOne) OR (numberThree + numberOne +numberTwo) OR (numberThree + numberThree + numberOne)){

    Also, the Or operator is || except with bytes and the And operator is && except with bytes. I don't know much about bytes so I can't answer about those.

    You'll have to replace userNumber == with userNumber.equals(values);

    and values be

    numberOne + "," + numberThree + "," + numberTwo;

    If that still won't work by replacing all of those, you'll have to make those values like shown above as Strings and use the equals method comparing userNumber.equals(thatString)

    else if ((inputOne == numberOne) OR (inputTwo == numberTwo) OR (inputThree == numberThree)){

    inputOne is a String. numberOne is an int. They will never be equal as your code currently is.

    They have to be the same type.

    Using the Integer wrapper class, you could do this;

    Integer n1 = numberOne;

    String n1String = n1.toString();

    inputOne.equals(n1String)


    Hope that helps.

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Loopy Lotto....

    Using the Integer wrapper class, you could do this;

    Integer n1 = numberOne;

    String n1String = n1.toString();

    inputOne.equals(n1String)
    You don't even need to do that. Just:
    inputOne.equals(numberOne+"");

    You can just add a blank String to any object to automatically call its toString() method. For simple types, they are already represented in the same way as their Wrapper Class's toString() method so it it not necessary to use a Wrapper class.

    I only ever use Wrapper Classes for Lists (ArrayLists, Vectors, ect.) that do not support simple types.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  5. The Following User Says Thank You to aussiemcgr For This Useful Post:

    javapenguin (October 18th, 2010)

  6. #5
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Loopy Lotto....

    Do you know how to get a String to print in reverse order? http://www.javaprogrammingforums.com...-problems.html

    Right now I have no clue why it's not storing anything in str for values other than 1 or 2.

    Also, I think even if I had it right, it'll be printing the binary value of the number backwards, unless I can figure out how to switch calling something till the right time.

Similar Threads

  1. new program (lotto.class)
    By james137 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 3rd, 2009, 05:22 PM

Tags for this Thread