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 7 of 7

Thread: Can i get some help with an array code

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Can i get some help with an array code

    im new to java and i have trouble with array not sure if i need to make a new static class i believe i do but my code works exactly as i want it to but im missing 2 things a counter counting the number of times my "numholder" variable comes up and as which number ie: 2 came up 3 times till the user hits quit
    not sure if i should put it in an array or write in a counter because it has to count both the straight line and if the user chooses to "bet" on another number without spinning i put in the option alrdy under my "additional" variable but i think thats were i need my array not sure if theres another way to do it would appreciate some help

    if (bet == 'a'|| bet == 's')
     
    										{
     
    											if (bet == 'a')
    											{ 
     
    												System.out.println("If you bet a number leave a space between each number");
    												s=scan2.toString();
    												String arrayString[] = s.split("\\s+"); 
     
     
    												String[] items = s.split("\\s+");
     
    												int[] results = new int[items.length];
     
    												for (int i = 0; i < items.length; i++) 
    												{
     
    												    try {
    												        results[i] = Integer.parseInt(items[i]);
    												    } catch (NumberFormatException nfe) {};
     
     
    											amountholder= howmuch* arrayString.length;
    												}			
    														if (amountholder>iamount)
    															{ 
    																System.out.println("You bet to much");	
    															}	
     
    															else {
    															int numholder1 = rand.nextInt(odds) + 1;		
    															int[] array = results;
    																	int value =numholder;
     
    																	int index = Arrays.asList(array,betnum).indexOf(numholder);
    																	System.out.println("You got" + numholder1);
    																	if(index>0);
    																	{      
    																		wins++;
     
    																		newcash=iamount +(howmuch* (odds-1));
     
    																		System.out.println("Congratz you Won" + " "+ (howmuch* (odds-1)));
    																	}                                      
     
    																	if(index<0) 
    																	             {
    																		newcash= (iamount-howmuch);
    																		lose++;
    																		System.out.println("Sorry you lost" +" " + howmuch);
     
    																	              }                
    																	}
     
    										System.out.println("You now have "+ newcash + "$");
     
    										System.out.println("Type: b to bet");
    										System.out.println("Type q to quit");
    										userinput = scan1.nextLine().charAt(0);
    Last edited by iamlost123; May 5th, 2014 at 08:54 PM.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Can i get some help with an array code

    Thanks for posting your code correctly, but your problem statement/question is very hard to read and understand. Can you add some punctuation, maybe ask an actual question so that we know what you need help with? Showing actual output versus desired might be helpful.

  3. #3
    Junior Member
    Join Date
    May 2014
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can i get some help with an array code

    Enter Wheel Size/odds
    2
    Do you want to play?
    Type: b to bet
    Type q to quit
    b
    How much do you want to bet?(1-500)
    12
    You bet 12$
    What number do you want to bet on ?1-2
    1
    You bet on 1
    Do you want to bet on another number?
    If yes type: a
    To spin type: s
    // this is were i need the help when you hit a do you need to throw each extra bet into an array or can you use some type of if statement?

    To spin type: s
    s
    You got1
    Congratz you Won 12
    You now have 512$
    You chose to quit
    Do you want to play?
    Type: b to bet
    Type q to quit
    q
    Wins: 1Losses : 0
    // this is were i need the counter to say 2 came up 3times or however many times your spinned till u quit
    Net gains :12

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Can i get some help with an array code

    do you need to throw each extra bet into an array or can you use some type of if statement?
    The bets need to be stored somewhere and that somewhere could be an array.
    i need the counter to say 2 came up 3times or however many times your spinned till u quit
    Similarly, multiple results that correspond to multiple bets need to be stored somewhere. Parallel arrays, one for bets and the other for results, are not my favorite solution, but I suspect that it's appropriate for your level.

    To pursue the parallel array approach, you'll need to decide the maximum number of bets that can be placed to size the arrays, OR use a collection that can vary in size, like an ArrayList.

  5. #5
    Junior Member
    Join Date
    May 2014
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can i get some help with an array code

    thats what i figured but i suck with arrays im trying some various ways but i keep screwing it up any possible examples?

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Can i get some help with an array code

    You'll suck less if you practice using them and gain confidence through experience. Someone showing you examples won't help your confidence or gain you experience.

  7. #7
    Junior Member
    Join Date
    May 2014
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can i get some help with an array code

    lol yeah but it will give me an idea of what to do right now im lost looking at array turtorials not helping much

Similar Threads

  1. Help with 2d Array Code
    By scubagabriella in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 21st, 2014, 12:19 PM
  2. Replies: 4
    Last Post: November 14th, 2011, 10:00 PM
  3. Please help with array code
    By senecawolf in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 12th, 2011, 02:01 AM
  4. Help with array code.
    By beginnerjava in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 2nd, 2011, 05:50 AM
  5. Array Code Help
    By whattheeff in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 21st, 2011, 04:44 PM