Question: JAVA CARD GAME ASSIGNMENT - Im needing some guidance on my class assignment for a Java Hi-Lo Card Game. This is written in Netbeans and
JAVA CARD GAME ASSIGNMENT - Im needing some guidance on my class assignment for a Java Hi-Lo Card Game. This is written in Netbeans and I need to figure out how to deal out the cards and give them a value to compare the two cards against eachother to determine the winner! I have the card deck, main, and player classes. Just need help with the next steps I need to take. I need a Card Class? That sets the values?
Basics:
For each hand (or round)
Deck is shuffled.
Game logic occurs
Winner is announced
Prompt users to play again
/////////////////////////////MAIN CLASS///////////////////////////////////////////////////
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String again;
Players p1 = new Players();
Players p2 = new Players();
Scanner sc = new Scanner(System.in);
System.out.print("Enter your first Players Name: ");
String player1 = sc.nextLine();
p1.setName(player1);
System.out.print("Enter your second Players Name: ");
String player2 = sc.nextLine();
p2.setName(player2);
System.out.println("First players name is: " + p1.getName());
System.out.println("Second players name is: " + p2.getName());
System.out.println("---------------------------------------");
do {
String[] deck = CardDeck.getDeck();
CardDeck.shuffleDeck(deck);
//* DEAL PLAYERS CARDS AND INPUT GAME LOGIC *//
System.out.println("Do you wish to play again?");
again = sc.next();
} while (again.equalsIgnoreCase("y"));
}
}
////////////////////////////////PLAYER CLASS////////////////////////////////////////////
public class Players {
String name;
public void setName(String n){
name = n;
}
public String getName(){
return name;
}
}
/////////////////////////////CARD DECK CLASS///////////////////////////////////////////
import java.util.Arrays;
public class CardDeck {
public static String[] getDeck() {
String[] suits = {"Spades", "Hearts", "Diamonds", "Clubs"};
String[] ranks = {"Ace", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "Jack", "Queen", "King"};
String[] deck = new String[52];
int i = 0;
for (String suit : suits) {
for (String rank : ranks) {
deck[i] = rank + " of " + suit;
i++;
}
}
return deck;
}
public static void displayCards(String[] cards) {
System.out.print("|");
for (String card : cards) {
System.out.print(card + " ");
}
System.out.println();
}
public static void shuffleDeck(String[] deck) {
for (int i = 0; i < deck.length; i++) {
String savedCard = deck[i];
int randomIndex = (int) (Math.random() * deck.length-1);
deck[i] = deck[randomIndex];
deck[randomIndex] = savedCard;
}
}
public static String[] dealCard(String[] deck, int count) {
String[] hand = Arrays.copyOfRange(deck, 0, count);
return hand;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
