Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › Need help writing a java program
New Posts  All Forums:Forum Nav:

Need help writing a java program

post #1 of 6
Thread Starter 
To generate random numbers, you construct an object of the Random class, and then apply one of the following methods:

nextInt(n): A random integer between the integers 0 (inclusive) and n (exclusive)
nextDouble(): A random floating-point number between 0 (inclusive) and 1 (exclusive)

Write a program that simulates the drawing of one card (for example, an ace of spades).
post #2 of 6
What exactly are you stuck with? I'm more than willing to help you out if you give more specifics rather than the entire problem.

Edit: Here's what I came up with really quickly. Not sure if it completely suits the problem, but it may help you in the right direction.

http://pastebin.com/JH2VJWLZ
Edited by 0CALEFACTION0 - 5/23/13 at 10:02am
Ivy(saur)
(17 items)
 
Brother's Build
(14 items)
 
 
CPUMotherboardGraphicsRAM
Core i5 2500k ASRock P67 Extreme4 EVGA GeForce GTX 460 SE G.SKILL Sniper (2x4gb) 1600MHz 
Hard DriveOptical DriveCoolingOS
Samsung Spinpoint F3 1TB LG CD/DVD Burner Hyper 212+ Windows 7 Home Premium-64bit 
MonitorPowerCase
Dell S2309W 23in 1080P Antec EarthWatts 650W Cooler Master HAF 912 
  hide details  
Reply
Ivy(saur)
(17 items)
 
Brother's Build
(14 items)
 
 
CPUMotherboardGraphicsRAM
Core i5 2500k ASRock P67 Extreme4 EVGA GeForce GTX 460 SE G.SKILL Sniper (2x4gb) 1600MHz 
Hard DriveOptical DriveCoolingOS
Samsung Spinpoint F3 1TB LG CD/DVD Burner Hyper 212+ Windows 7 Home Premium-64bit 
MonitorPowerCase
Dell S2309W 23in 1080P Antec EarthWatts 650W Cooler Master HAF 912 
  hide details  
Reply
post #3 of 6
Since you're permitted to use the java.util.Random class (which includes the nextInt() function) then it should be a trivial application to write.

Simply enumerate your 52 playing cards to an array, select your random integer from 1..52 and then display the array content. Make a two-dimensional array and hold a "chosen" bit in one of the dimensions if you need to shuffle the entire deck and display ALL of the cards w/o duplicating a card in the draw.

Java final? Lol.

Greg
post #4 of 6
Quote:
Originally Posted by hammong View Post

Since you're permitted to use the java.util.Random class (which includes the nextInt() function) then it should be a trivial application to write.

Simply enumerate your 52 playing cards to an array, select your random integer from 1..52 and then display the array content. Make a two-dimensional array and hold a "chosen" bit in one of the dimensions if you need to shuffle the entire deck and display ALL of the cards w/o duplicating a card in the draw.

Java final? Lol.

Greg

Man I wish my last Java final was that easy. I wrote an entire networked GUI card game.
Ivy(saur)
(17 items)
 
Brother's Build
(14 items)
 
 
CPUMotherboardGraphicsRAM
Core i5 2500k ASRock P67 Extreme4 EVGA GeForce GTX 460 SE G.SKILL Sniper (2x4gb) 1600MHz 
Hard DriveOptical DriveCoolingOS
Samsung Spinpoint F3 1TB LG CD/DVD Burner Hyper 212+ Windows 7 Home Premium-64bit 
MonitorPowerCase
Dell S2309W 23in 1080P Antec EarthWatts 650W Cooler Master HAF 912 
  hide details  
Reply
Ivy(saur)
(17 items)
 
Brother's Build
(14 items)
 
 
CPUMotherboardGraphicsRAM
Core i5 2500k ASRock P67 Extreme4 EVGA GeForce GTX 460 SE G.SKILL Sniper (2x4gb) 1600MHz 
Hard DriveOptical DriveCoolingOS
Samsung Spinpoint F3 1TB LG CD/DVD Burner Hyper 212+ Windows 7 Home Premium-64bit 
MonitorPowerCase
Dell S2309W 23in 1080P Antec EarthWatts 650W Cooler Master HAF 912 
  hide details  
Reply
post #5 of 6
Quote:
Originally Posted by 0CALEFACTION0 View Post

Man I wish my last Java final was that easy. I wrote an entire networked GUI card game.

My programming final I wrote an educational racing simulator using DirectX, loosely based on Action Fighter - an old Sega Master System game. This wasn't written in Java though smile.gif
post #6 of 6
My main problem was the two other final projects I was working on whereas this was a group project that I ended up coding myself.
Ivy(saur)
(17 items)
 
Brother's Build
(14 items)
 
 
CPUMotherboardGraphicsRAM
Core i5 2500k ASRock P67 Extreme4 EVGA GeForce GTX 460 SE G.SKILL Sniper (2x4gb) 1600MHz 
Hard DriveOptical DriveCoolingOS
Samsung Spinpoint F3 1TB LG CD/DVD Burner Hyper 212+ Windows 7 Home Premium-64bit 
MonitorPowerCase
Dell S2309W 23in 1080P Antec EarthWatts 650W Cooler Master HAF 912 
  hide details  
Reply
Ivy(saur)
(17 items)
 
Brother's Build
(14 items)
 
 
CPUMotherboardGraphicsRAM
Core i5 2500k ASRock P67 Extreme4 EVGA GeForce GTX 460 SE G.SKILL Sniper (2x4gb) 1600MHz 
Hard DriveOptical DriveCoolingOS
Samsung Spinpoint F3 1TB LG CD/DVD Burner Hyper 212+ Windows 7 Home Premium-64bit 
MonitorPowerCase
Dell S2309W 23in 1080P Antec EarthWatts 650W Cooler Master HAF 912 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › Need help writing a java program