-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deals random Cards based on Array with suit, ranks, and positions.
- Loading branch information
Colleen Blaho
committed
Feb 13, 2013
1 parent
5957782
commit a5c5e9f
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import java.util.Scanner; | ||
|
||
public class Q3A3A { | ||
public static void main(String[] args) { | ||
|
||
Scanner myInput = new Scanner(System.in); | ||
System.out.println("How many cards would you like to see?"); | ||
int numCards = myInput.nextInt(); | ||
int[] deck = new int[52]; | ||
|
||
|
||
deck = InitializeCards(deck); | ||
|
||
deck = ShuffleTheDeck(deck); | ||
|
||
DisplayTheCards(deck, numCards); | ||
} //EOM | ||
|
||
public static int[] InitializeCards(int[] list) { | ||
for (int i = 0; i < list.length; i++) { | ||
list[i] = i; | ||
} //EOFL | ||
return list; | ||
} //EOIC | ||
|
||
public static int[] ShuffleTheDeck(int[] list) { | ||
for (int i = 0; i < list.length; i++){ | ||
int index = (int)(Math.random() * list.length); | ||
int temp = list[i]; | ||
list[i] = list[index]; | ||
list[index] = temp; | ||
} //EOFL | ||
return list; | ||
} // EOSTD | ||
|
||
public static void DisplayTheCards(int[] list, int number) { | ||
String[] suits = {"Spades" , "Hearts" , "Diamonds" , "Clubs"}; | ||
String[] ranks = {"Ace" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" , "Jack", "Queen", "King"}; | ||
//variable scope. This is where it gets used, this is where it's going. #yoco | ||
for (int i = 0; i < number; i++) { | ||
String suit = suits[list[i] / 13]; | ||
String rank = ranks[list[i] % 13]; | ||
System.out.println("Card number" + list[i] + ": " + rank + " of " + suit); | ||
} //EOFL | ||
return; | ||
} //EODTC | ||
|
||
} //EOF | ||
|