• Post Reply Bookmark Topic Watch Topic
  • New Topic

problems with arrays  RSS feed

 
Chris Lavery
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
he every1,
can sum1please helpme here, i am really stuck.
i have a quston to do and iv no idea how to even start.
the question:
A standard pack of cards can be represented as an array of 52 integers with each number representing a standard card. Thus:

0 1 2 3 4 5 6 7 8 9 10 11 12 ..... 39 40 41 42 43 44 45 46 47 48 49 50 51

We can shuffle this pack of cards by randomly generating two indexes and swapping those two cards. For example if we randomly generate the indexes 8 and 50 and swap these two "cards" we would get (assuming this is the first swap):

0 1 2 3 4 5 6 7 50 9 10 11 12 ..... 39 40 41 42 43 44 45 46 47 48 49 8 51

After a suitable number of swaps have been made the pack can be said to be "shuffled".

Design and implement a Java programme which takes as input the number of desired swaps, outputs an ordered Set of cards which are then "shuffled" and output again. The number of swaps must be at least 1 and not more than 1000.
please please please help me with this.
any help at all is much appreciated
chris
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

It's a bit hard to understand your "IM-speak", but I'll do my best. If you can, when you reply, please spell words out to make it clear what you're saying. Thanks.

Now, on to your problem. The problem statement sounds very clear, actually. Assuming you know how to write, compile, and run "HelloWorld" in Java, the first problem is how to input the size of the array, yes? Is that where you're stuck?
 
Chris Lavery
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for your reply.
yes, i can understand and compile and execute the HelloWorld program, my problem here is that i cant actually understand what to do full stop. i know i have to shuffle the cards, its just this is my first study of arrays and i cant get my head around it. im just stuck.i dont know where to begin
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, well, as I said, the first thing would be prompting for and reading the size of the array from the user. Do you know how to do that?
 
Chris Lavery
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no, sadly not, this is my first time with arrays so everything is new to me
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. Note, though, that this first part has nothing to do with arrays.

Go have a look here and here, and see if you can put together a program that prompts for an int, reads it, and prints it back out. That'd be a start.
 
Chris Lavery
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, i ve got that done
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. Now allocate an array of that size, and use a loop to set the value of each cell in the array. Then use another loop to print out the value of each cell in the array. Now you've got a program that creates a "deck" of the appropriate size, and displays it.

By the way, it'd be OK for you to post each bit here as you get it.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!