Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › small Java function, need assistance
New Posts  All Forums:Forum Nav:

small Java function, need assistance

post #1 of 3
Thread Starter 
I'm writing a function that "Deal 100000 '5 card hands', count and print how many have (at least) one pair. ( should be about 49%)".

For testing purposes while writing the program, I'm only dealing 100 5 card hands. The problem is, the function isn't counting the number of pairs right and counting to 100,000 would probably take more than an hour.

The instructions say "Hint: shuffle the deck and clear the hand each iteration: see Deck, Hand documentation details", however, the clear function in the Hand class isn't static so I can't access it so it doesn't do me any good.

Here's my code as of right now:



And here's the hasOnePair function:

Thanks
Edited by skatingrocker17 - 2/5/12 at 8:38pm
    
CPUMotherboardGraphicsGraphics
Core i7 930 @ 4004Mhz 1.29 V Gigabyte GA-X58A-UD3R XFX Radeon 6970 nVidia 8800GTX 
RAMHard DriveOptical DriveOptical Drive
G. SKILL 6GB 1333Mhz @ 1455Mhz OCZ Vertex 3 120GB / Seagate 500GB Lite-On DVD-RW TSSTcorp DVD/RW 
CoolingOSMonitorMonitor
Prolimatech Megahalems Windows 7 x64 Professional Samsung S24A350H Dell 20" LCD 
MonitorMonitorKeyboardPower
MAG 17" LCD Samsung 50" Plasma  Focus FK-2001 Mechanical Corsair TX750 
CaseMouseMouse PadAudio
Cooler Master Storm Scout (Modded) Razer Abyssus Disney's Mickey Mouse with circuits JVC MX-GT700 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
Core i7 930 @ 4004Mhz 1.29 V Gigabyte GA-X58A-UD3R XFX Radeon 6970 nVidia 8800GTX 
RAMHard DriveOptical DriveOptical Drive
G. SKILL 6GB 1333Mhz @ 1455Mhz OCZ Vertex 3 120GB / Seagate 500GB Lite-On DVD-RW TSSTcorp DVD/RW 
CoolingOSMonitorMonitor
Prolimatech Megahalems Windows 7 x64 Professional Samsung S24A350H Dell 20" LCD 
MonitorMonitorKeyboardPower
MAG 17" LCD Samsung 50" Plasma  Focus FK-2001 Mechanical Corsair TX750 
CaseMouseMouse PadAudio
Cooler Master Storm Scout (Modded) Razer Abyssus Disney's Mickey Mouse with circuits JVC MX-GT700 
  hide details  
Reply
post #2 of 3
You're doing integer division, which truncates the remainder. No matter what, on that if-else statement, you're going to get the same number printed to the user. The only difference will be if it is followed by "00" or not. Lose the If-else, and just print out (numPairs + " of poker hands out of 100 contained pairs")
College Rig
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel i7-930 @ 4.2Ghz, Stable ASUS P6X58D-E EVGA GTX 460 SSC 1024MB & EVGA GTX 460 SC 1024MB OCZ Gold 6GB (3 x 2GB) 240-Pin DDR3 1600 
Hard DriveOptical DriveOSMonitor
Intel X25-M Mainstream 80GB SATA II SSD ASUS USB 2.0 External Slim DVD±R/RW Windows 7 Ultimate 64-Bit 3x SAMSUNG P2570HD Black 24.6" 4ms HDMI Widescreen 
KeyboardPowerCaseMouse
Eclipse Lite-Touch (Wired) CORSAIR 850HX Corsair 800D Razer Naga 
  hide details  
Reply
College Rig
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel i7-930 @ 4.2Ghz, Stable ASUS P6X58D-E EVGA GTX 460 SSC 1024MB & EVGA GTX 460 SC 1024MB OCZ Gold 6GB (3 x 2GB) 240-Pin DDR3 1600 
Hard DriveOptical DriveOSMonitor
Intel X25-M Mainstream 80GB SATA II SSD ASUS USB 2.0 External Slim DVD±R/RW Windows 7 Ultimate 64-Bit 3x SAMSUNG P2570HD Black 24.6" 4ms HDMI Widescreen 
KeyboardPowerCaseMouse
Eclipse Lite-Touch (Wired) CORSAIR 850HX Corsair 800D Razer Naga 
  hide details  
Reply
post #3 of 3
Thread Starter 
Any idea on why it's saying every hand contains a pair? I've tested my pair function manually and it works. I think there's something wrong with the poker hand not getting cleared after each iteration but that's because I can't call the clear function because it's not static.

Edit: figured it out, it all had to do with placement of the pokerHand tester1 = new pokerHand();
    
CPUMotherboardGraphicsGraphics
Core i7 930 @ 4004Mhz 1.29 V Gigabyte GA-X58A-UD3R XFX Radeon 6970 nVidia 8800GTX 
RAMHard DriveOptical DriveOptical Drive
G. SKILL 6GB 1333Mhz @ 1455Mhz OCZ Vertex 3 120GB / Seagate 500GB Lite-On DVD-RW TSSTcorp DVD/RW 
CoolingOSMonitorMonitor
Prolimatech Megahalems Windows 7 x64 Professional Samsung S24A350H Dell 20" LCD 
MonitorMonitorKeyboardPower
MAG 17" LCD Samsung 50" Plasma  Focus FK-2001 Mechanical Corsair TX750 
CaseMouseMouse PadAudio
Cooler Master Storm Scout (Modded) Razer Abyssus Disney's Mickey Mouse with circuits JVC MX-GT700 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
Core i7 930 @ 4004Mhz 1.29 V Gigabyte GA-X58A-UD3R XFX Radeon 6970 nVidia 8800GTX 
RAMHard DriveOptical DriveOptical Drive
G. SKILL 6GB 1333Mhz @ 1455Mhz OCZ Vertex 3 120GB / Seagate 500GB Lite-On DVD-RW TSSTcorp DVD/RW 
CoolingOSMonitorMonitor
Prolimatech Megahalems Windows 7 x64 Professional Samsung S24A350H Dell 20" LCD 
MonitorMonitorKeyboardPower
MAG 17" LCD Samsung 50" Plasma  Focus FK-2001 Mechanical Corsair TX750 
CaseMouseMouse PadAudio
Cooler Master Storm Scout (Modded) Razer Abyssus Disney's Mickey Mouse with circuits JVC MX-GT700 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › small Java function, need assistance