Questions about Collections.shuffel and error message

I am trying to get my poker game to work but it comes up with an error when it trys to score the hand
*public class PokerTester{*
Deck deck *=* new Deck*();*
public PokerTester*()*
playGame*();*
public void playGame*()*
*{*+//stacks hand+
Hand hand *=* new Hand*();*
for(int i*=* 0*;* i*<* 5*;* i*++)*
hand*.*add*(*deck*.*getTopCard*());*
System*.*out*.*println*(*"Player's Hand:"*);*
hand*.*showHand*();*
public static void main*(*String*[]* args*)*
new PokerTester*();*
public class Hand*{*
ArrayList<Card> hand=new ArrayList<Card>();
int[] values = new int[5];
public void add(Card card)
hand.add(card);
+
public String getHandValue()
+
String win= "";
for(int i= 0; i<5; i++)
*values=values[((Card)hand.get(i)).getValue()];*
Arrays.sort(values);
if(checkRoyalStraight()&&checkFlush()) win="Royal Flush";
else if(checkFlush()&&checkStraight()) win="Straight Flush";
else if(checkOfAKind(4)) win = "4 of a Kind";
else if(checkFullHouse()) win = "Full House";
else if(checkFlush()) win = "Flush";
else if(checkStraight()) win = "Straight";
else if(checkOfAKind(3)) win = "3 of a Kind";
else if(checkOfAKind(2)) win = "Pair";
else win = "High Card";
return win;
+
public boolean checkOfAKind(int n)
+
boolean kind=false;
if(n==4)
if(values[0]==values[3]||values[1]==values[4])
kind=true;
if(n==3)
if(values[0]==values[2]||values[1]==values[3]||values[2]==values[4])
kind=true;
if(n==2)
for(int i=0; i<4; i++)
*if(values[i]==values[i+1])*
kind=true;
return kind;
public boolean checkFullHouse()
boolean fullhouse=false;
if(values[0]==values[2]&&values[3]==values[4])
fullhouse=true;
else
if(values[2]==values[4]&&values[0]==values[1])
fullhouse=true;
return fullhouse;
public boolean checkFlush()
int suit = ((Card)hand.get(0)).getSuit();
for(int i=1; i<5; i++)
if(((Card)hand.get(i)).getSuit() != suit)
return false;
return true;
public boolean checkStraight()
int count=0;
for(int i=0; i<4; i++)
*if(values[i]+1==values[i+1])*
count++;
if(count==4)
return true;
else return false;
public boolean checkRoyalStraight()
int n=10;
for(int i=0; i<5; i++)
*if(values[i]==10)*
n++;
if(n==15)
return true;
else return false;
+
public void showHand() +
+
+
for(int i= 0; i<5; i++)
int suit=hand.get(i).getSuit();
String s="";
if(suit==0)
s="Hearts";
else if(suit==1)
s="Spades";
else if(suit==2)
s="Clubs";
else s="Diamonds";
System.out.println(((Card)hand.get(i)).getValue()+" of "+s);
System.out.println("Hand value: "+getHandValue());
public class Deck
Card*[]* cards *=* new Card*[*52*];*
ArrayList*<*Card*>* deck *=* new ArrayList*<*Card*>();*
public Deck*()*
for(Integer i*=*0*;* i*<*4*;* i*++)*
for(Integer n*=*1*;* n*<=*13*;* n*++)*
deck*.*add*(new* Card*(*n*,* i*));*
+
Collection*.*shuffle*(*deck*);*
+
public Card getTopCard*()*
Card topCard *=*deck*.*get*(*0*);*
deck*.*remove*(*0*);*
return topCard*;*
public class Card*{*
private int value;
private int suit;
public Card(int value,int suit)
this.value=value;
this.suit=suit;
public int getValue()
return value;
public int getSuit()
return suit;
{color:#000000}
This is what i get when I run the program{color}
1 of Hearts
2 of Hearts
3 of Hearts
4 of Hearts
5 of Hearts
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at Hand.getHandValue(Hand.java:22)
at Hand.showHand(Hand.java:145)
at PokerTester.playGame(PokerTester.java:16)
at PokerTester.<init>(PokerTester.java:6)
at PokerTester.main(PokerTester.java:21)
Also I cannot get the Collections.shuffle() to work correctly does anyone know how to use this properly, Thank you

When you use the letter "i" for an array index without using the code tags, the forum interprets that to mean "start italic" and your code is mangled - converted to italic and changed.
Repost using code tags:
[code]
Put your code here
[/code]
This error
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5means that an array index value is greater than the max value allowed for the array.
If you can't fix this, identify the line where the error is happening (it's line 5)

Similar Messages

  • Questions about Tuxedo patches and errors during installation

    Hi,
    Please help me. I'm doing my school project that requires me to install PeopleSoft Human Capital Management. I do not have customer identifier. Therefore, I could not sign in to Oracle Support. Really appreciate your help!!! Thank you in advance!
    Q1. Are Tuxedo patches able to download from Oracle support only?
    Q2. Is Tuxedo patch compulsory?
    I have few errors in the following:
    Q3. For the documentation (V27932-01 PeopleSoft PeopleTools 8.52 Supplemental Installation Information --> PeopleTools_8.52_Installation_MSS --> Task 7-5-1: Running SQRs on the Client Workstation), I got this error when I use sqrw.exe:
    Error in include file "setenv.sqc on line 408:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    dyn-datein-prefix
    Error in include file "setenv.sqc" on line 409:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    dyn-datein-suffix
    Error in include file "setenv.sqc" on line 410:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    timeout-prefix
    Error in include file "setenv.sqc" on line 411:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    timeout-suffix
    Error in include file "setenv.sqc" on line 412:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    dyn-timeout-prefix
    Error in include file "setenv.sqc" on line 413:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    dyn-timeout-suffix
    Error in include file "setenv.sqc" on line 414:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    timein-prefix
    Error in include file "setenv.sqc" on line 415:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    timein-suffix
    Error in include file "setenv.sqc" on line 416:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    dyn-timein-prefix
    Error in include file "setenv.sqc" on line 417:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    dyn-timein-suffix
    Error in include file "setenv.sqc" on line 418:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    time24out-prefix
    Error in include file "setenv.sqc" on line 419:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    time24out-suffix
    Error in include file "setenv.sqc" on line 420:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    dyn-time24out-prefix
    Error in include file "setenv.sqc" on line 421:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    dyn-time24out-suffix
    Error in include file "setenv.sqc" on line 422:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    time24in-prefix
    Error in include file "setenv.sqc" on line 423:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    time24in-suffix
    Error in include file "setenv.sqc" on line 424:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    dyn-time24in-prefix
    Error in include file "setenv.sqc" on line 425:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    dyn-time24in-suffix
    Error in include file "setenv.sqc" on line 428:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    binarysort-prefix
    Error in include file "setenv.sqc" on line 429:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    binarysort-suffix
    Error in include file "ptset01.sqc" on line 38:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    ptsetxx-included
    Error in include file "ptset01.sqc" on line 92:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    page_orientation
    Error in include file "ptset01.sqc" on line 92:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    colr
    Error in include file "ptset01.sqc" on line 92:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    page_paper_size
    Error in include file "ptset01.sqc" on line 92:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    line_height
    Error in include file "ptset01.sqc" on line 92:
    <SQR 3601> Out of substitution or #DEFINE variables; use -Mfile to increase SUBVARS.
    char_width
    Error in include file "ptset01.sqc" on line 116:
    <SQR 4707> No value found for substitution variable: {page_paper_size}
    paper-size={PAGE_PAPER_SIZE}
    Error in include file "ptset01.sqc" on line 117:
    <SQR 5312> Qualifier 'paper-size' requires a list of values: <val [,val]...>.
    paper-size={PAGE_PAPER_SIZE}
    Error in include file "ptset01.sqc" on line 117:
    <SQR 4707> No value found for substitution variable: {page_orientation}
    orientation={PAGE_ORIENTATION}
    Error in include file "ptset01.sqc" on line 118:
    <SQR 5302> Incorrect value for qualifier 'orientation'. Valid values are: portrait landscape
    orientation={PAGE_ORIENTATION}
    Error in include file "ptset01.sqc" on line 118:
    <SQR 4707> No value found for substitution variable: {line_height}
    line-height={LINE_HEIGHT}
    Error in include file "ptset01.sqc" on line 119:
    <SQR 5316> Qualifier 'line-height' uses an invalid Unit-Of-Measure suffix.
    Valid suffixes are: dp pt mm cm in
    line-height={LINE_HEIGHT}
    Error in include file "ptset01.sqc" on line 119:
    <SQR 4707> No value found for substitution variable: {char_width}
    char-width={CHAR_WIDTH}
    Error in include file "ptset01.sqc" on line 120:
    <SQR 5316> Qualifier 'char-width' uses an invalid Unit-Of-Measure suffix.
    Valid suffixes are: dp pt mm cm in
    char-width={CHAR_WIDTH}
    <SQR 1806> Out of query space. Use -Mfile to increase QUERIES.
    SQR for PeopleSoft: Program Aborting.
    Press ENTER to close...
    Q4. For the documentation (V27932-01 PeopleSoft PeopleTools 8.52 Supplemental Installation Information --> PeopleTools_8.52_Installation_MSS --> Task 8-4-1: Creating, configuring, and Starting the Application Server Domain), I can't boot when I use psadmin application and got this error:
    (i choose serial boot (1), don't know which is better to choose)
    Command to execute <1-2, q> [q]: 1
    Attempting to boot bulletin board...
    tmadmin - Copyright <c> 2007-2008 Oracle.
    Portions * Copyright 1986-1997 RSA Data Security, Inc.
    All Rights Reserved.
    Distributed under license by Oracle.
    Tuxedo is a registered trademark.
    No bulletin board exists. enter boot mode.
    INFO: Oracle Tuxedo, Version 10.3.0.0 with VS2008, 32-bit, Patch Level <none>Booting admin processes ...
    exec BBL -A :
    process id=4952 ... Started.
    1 process started.
    Attaching to active bulletin board.
    Attempting to boot ...INFO: Oracle Tuxedo, Version 10.3.0.0 with VS2008, 32-bit, Patch Level <none>
    Booting server processes ...
    exec PSWATCHSRV -o ".\LOGS\stdout" -e ".\LOGS\stderr" -A -- -ID 35931 -D TESTSERV -S PSWATCHSRV :
    process id=4076 ... Started.
    exec PSAPPSRV -o ".\LOGS\stdout" -e ".\LOGS\stderr" [email protected] -- -D TESTSERV -S PSAPPSRV :
    CMDTUX_CAT:1685: ERROR: Appliction initialization failure
    tmboot: CMDTUX_CAT:827: ERROR: Fatal error encountered; initiating user error handler
    tmshutdown -qy

    you said3. I run the SQR by pressing the PS_HOME\bin\sqr\MSS\binw\sqrw.exe and I type in my report name, datasource, username and password then click ok then the command came out.
    >
    What you didn't do was set the SQR arguments in the Report Arguments section. You need to supply the arguments as follow:
    -ZIF%PS_HOME%\sqr\pssqr.ini -i%PS_HOME%\sqr -fc:\temp\youroutput.htm -printer:ht -keep
    You have to do this for each SQR you want to start.
    To avoid typing these arguments every time, create a shortcut of sqrw.exe, on your desktop, or where ever your like and open the properties of the shortcut and change to command line to
    %PS_HOME%\bin\sqr\ORA\binw\sqrw.exe -ZIF%PS_HOME%\sqr\pssqr.ini -i%PS_HOME%\sqr -fc:\temp\youroutput.htm -printer:ht -keep
    Now when you dubble click on the shortcut the arguments will be filled in automatically.
    Change %PS_HOME% in above statements to your PS_HOME.
    You can also read this in the installation manual in chapter Task 7A-21-1: Running SQRs on the Client Workstation

  • TS2755 Good morning I have a question about my IPhone4 and text messaging screen.

    My touch screen is frozen( locked up) when it comes to trying to scroll up and down to check text messages and to delete. I cannot access them at all. The rest of the phone and features are operating and functioning properly. Just issues with the text messaging option. Any suggestions?

    Hi JSWhitfield,
    Thanks for visiting Apple Support Communities.
    If Messages is unresponsive, first force close the application using this method:
    Double-click the Home button.
    Swipe left or right until you have located the app you wish to close.
    Swipe the app's preview up to close it.
    These steps come from this article:
    iOS: Force an app to close
    http://support.apple.com/kb/ht5137
    If the correct information still does not appear after you open the Music app and play a song, restart your iPhone next:
    iOS: Turning off and on (restarting) and resetting
    http://support.apple.com/kb/ht1430
    All the best,
    Jeremy

  • I have design standard with creative cloud, I have installed this on 2 computers, my office and home which I was told was allowed, I have just tried to open an indesign file from the office at home and and error message said that this was created with a n

    I have design standard with creative cloud, I have installed this on 2 computers, my office and home which I was told was allowed, I have just tried to open an indesign file from the office at home and and error message said that this was created with a newer version? they are the same versions and both are up to date, I was asked this morning to put in my adobe id email and password to connect to CC which I have never been asked to do before, can anyone help?

    what's your home version (click help>about) and was that just a warning so you were able to open the file?

  • Trying to send e-mail and error message " a copy has been placed in your outbox. the sender address was rejected by the server"

    trying to send e-mail and error message " a copy has been placed in your outbox. the sender address was rejected by the server"

    i have the same problem with my 3gs and tried to add my email acc+pass in the outgoing server but it got rejected.
    just bin on the phone(45min) with my carrier support about this issue they are pretty much scratching there head, the settings i should use gets verified with no problems when i add the outgoung server, but still cant send mails.

  • TS2634 My problem - when syncing and error messages  comes up:  iTunes could not sync calendars to the iPhone because an error occurred while margin data."  I've tried turning the phone off and back on, & tried both USB ports but get the same thing.  What

    My problem - when syncing and error messages  comes up:  iTunes could not sync calendars to the iPhone because an error occurred while margin data."  I've tried turning the phone off and back on, & tried both USB ports but get the same thing.  What can I do next since it doesn't give me even one clue as to what the error would be?

    Before I started to resync calendars one by one as suggested in the troubleshooting article, I remembered something that came up in a sync when I first attempted :  a 'which one do you want to keep' message about a repeating calendar event, which came up with three options, one from Calendar, and two from iCal on the phone.  I deleted that event, then went through the calendar resync one by one, and all seems OK now.
    In Music there is a way to find 'ghost' items that show up as grayed-out on the menus, so that you can try to reassociate or delete them.  It would be nice to have a similar way to work with Calendar!
    Thanks for pointing me to the right article.

  • HT1390 trying to rent a movie and error message pops up saying "item cannot be downloaded on this network. You must connect to wi-fi or download it on your computer". I just finished downloading a rental but I get this message when attempting another. Any

    trying to rent a movie and error message pops up saying "item cannot be downloaded on this network. You must connect to wi-fi or download it on your computer". I just finished downloading a rental but I get this message when attempting another. Any help much appreciated

    You might want to try it again.  It started working for me about 10 minutes ago (~8pm CST).
    This was happening for rentals and purchases.

  • A question about item "type and release" of  source system creation

    Hello expert,
    I have a question about item "type and release" of  source system creation.
    As we know,when we create a web servie source system,there will display a pop-up which includes three items as "logical system","source system"and "type and release".
    About the item "type and release",when we push "F4" button,there will be three default selections as below:
    "ORA 115     Oracle Applications 11i
    TLF 205     Tealeaf 2.05B
    XPD 020     SAP xPD".
    Who can tell me when and how should I use the three selections.
    And also I attempted to input the item by some optional letters except the default three selections and it seems that I can input it freely.
    Thank you and Best Regards,
    Maggie

    Hello DMK,
    Thank you very much for your answer.It is very helpful for me.
    Can I ask you further about it?
    I got that it is a semantic description item.
    You said the default selections are set by our basis people.Would you like to tell me how should we creat a new value except the default ones for item "type and release"?Only by inputing the value in the item directly?But you see we canot see the new value item we created by ourself when we push "F4" button next time ,is that ok?Or do we have to ask basis people to define one new value item just like the default seletions before we use it.
    Also if possible would you like to describe detail about "This becomes important when you are troubleshooting certain issues especially when RFC connection problems."
    Thank you and Best Regards,
    Maggie
    Message was edited by: Maggie

  • I updated to iTunes 12 and didn't like it. Followed advice to revert to 11.1. Now my iphone won't sync and error message says I need iTunes 11.2 or higher. Apple Download choices didn't have anything between 11.1.5 and 12. What can I do?

    I updated to iTunes 12 and didn't like it. Followed advice to revert to 11.1. Now my iPhone 5 won't sync and error message says I need iTunes 11.2 or higher. Apple Download choices didn't have anything between 11.1.5 and 12. What can I do? Using iTunes 12 is not an option. Many features I used for audiobooks have disappeared.

    The version immediately prior to 12 was 11.4.0.18. Here are direct download links from Apple's servers:
    iTunes 11.4.0.18 for Windows (32-bit) - iTunesSetup.exe (2014-09-09)
    iTunes 11.4.0.18 for Windows (64-bit) - iTunes64Setup.exe (2014-09-09)
    tt2

  • I just upgraded my mac book to 10.6.8 and downloaded the new version of itunes. When I try to open it and error message appears saying, "The iTunes Library file cannot be found or created. The default location for this file is in the "iTunes" folder.

    I just upgraded my mac book to 10.6.8 and downloaded the new version of itunes. When I try to open it and error message appears saying, "The iTunes Library file cannot be found or created. The default location for this file is in the "iTunes" folder in the "Music" folder."
    I have tried a few things but iTunes closes right after i click okay. Anyone know anything?

    Look in your Home > Music folder.  There should be an iTunes folder there and it should have a number of files and folders including one called library.itl  You want to guide iTunes to that file.  If you don't see that file or folder then in your next post you will have to be very specific as to what you do see or how you have your iTunes set up because that's where it should be according to default settings.

  • Just purchased online Adobe Acrobat XI Pro and error message appeared, but payment has been debited from my credit card already

    Hello,
    Just purchased online Adobe Acrobat XI Pro and error message appeared, but payment has been debited from my credit card already and I do not have the software, so paid for nothing.
    I am using a Mac OS X.
    Thanks for your help.
    Ossama

    [discussion moved to Acrobat Installation & Update Issues forum]

  • I am trying to re-install Photoshop CS6. The files have downloaded but I get and error message that the Adobe Support Advisor is required to determine what the installation probIem is. I click on the link that says "get the Support Advisor here only to be

    I am trying to re-install Photoshop CS6. The files have downloaded but I get and error message that the Adobe Support Advisor is required to determine what the installation probIem is. I click on the link that says "get the Support Advisor here only to be told the Support Advisor no longer exists!! A blind loop. I need to have Photoshop CS6 installed...what do I do from here??

    The CC Cleaner Tool assumes the Akamai Download Manager is activated and it has not. It seems to be the missing file that triggers the error message. \in a previous re-install I was prompted to download & install the Akamai Download Manger, but not this time. Is there somewhere on the Adobe website that I can download it??

  • Every time I click on something in GarageBand and error message pops up that says "Error code 25974 was returned by the Audio driver." How do I fix this problem?

    Every time I click on something in GarageBand and error message pops up that says "Error code 25974 was returned by the Audio driver." How do I fix this problem?

    Every time I click on something in GarageBand and error message pops up that says "Error code 25974 was returned by the Audio driver." How do I fix this problem?

  • I have an iphone 4 and i just updated to ios5 and i can't get my music to stay on my iphone and i also keep getting and error message when trying to restore iphone. anyone else having this problem?

    i have an iphone 4 and i just updated to ios5 and i can't get my music to stay on my iphone and i also keep getting and error message when trying to restore iphone. anyone else having this problem?

    When you restore, which error # appears?

  • I try to open the program after installing it and I recieve and error message: Error: 213:11

    HELP! I try to open the program after installing it and I receive and error message: Error: 213:11

    This issue is covered under document: https://helpx.adobe.com/creative-suite/kb/error-store-does-not-allow.html
    This error occurs when the SLStore Folder is set to read-only. To resolve it, remove the read-only check from the SLStore folder (Windows) or give it read/write access (Mac OS). step in the link above.

Maybe you are looking for

  • Tab order shows correctly, but doesn't work in PDF

    Does anyone else have the problem, or know how to solve it, where you go through and set up the tab order correctly numbers for each page, but then when you tab through the preview pdf or the saved pdf, it will jump between pages instead of going thr

  • Photography Plan, Lightroom and Photoshop CC

    Hi Guys Hope someone can help me, I subscribe to Photography Plan, Lightroom and Photoshop CC, Lightroom says trial ended and the application will not work. Contacted Adobe, tried uninstalling and reinstalling application a cloud application to no av

  • Moving files manually in itunes?

    Hi, I have the latest itunes.. when I import music I do so with a folder for each artist or album. Most of the time itunes creates a complete folder for my import. There are a few tracks that did not go into their folders and were left outside as "un

  • Problem-Writing datas to a Servlet thro' URLConnection class

    Hi, Iam trying to post some string data to a servlet. The servlet reads 2 parameters from url.And reads the xml string message thro post method. So in the client program, I added those parameters to the URL directly like this, "http://localhost/servl

  • Spyder 2 work for Video Calibration on Mac display?

    I need to color correct my short accurately but I don't have a broadcast monitor. If I buy this Spyder 2 will it get me pretty close to accurate so I can get a good enough idea what the color is? Anybody use this project? cja