I am trying to write a program to play War. We have been charged to do the following;
Create a virtual "War" card game. The way it needs to work is the player and the computer each get 5 cards. The player and the computer each lay a card down - whoever has the higher card wins that hand and takes both the cards. This continues until someone has all of the cards. That is the winner.
We need to
Create a class named Card. This class consists of the following:
1. A String instance variable named suit, which holds the suit of the card (Hearts, Diamonds, Clubs, Spades)
2. A String instance variable named number, which holds the number of the card (2,3,4,...9,10,Jack,Queen,King,Ace)
3. A constructor that contains the following;
1. A String array that holds all of the suits
2. A String array that holds all of the numbers
3. Generates a random number that randomly represents the suit and assigns that suit to the suit instance variable using the suits array (think about this - the random number is an int and the array is full of Strings)
4. Generates a random number that randomly represents the number and assigns that number to the number instance variable using the suits array
4. A method named getCard that takes the Sstring number and converts it to an integer so it can be used to compare values when the game begins. Your task is to figure out the logic for this method.
Create a class named CardTestDrive. This class is responsible for playing the game.
1. The player and the computer start off with 5 cards each.
2. Every time there is a "War", instntiate a player card object and a computer card object
3. Using the objects' instance variables and method, compare the two cards number values. If it is a tie, disregard that particular war.
4. Based upon who wins, update the number of cards each player has.
My can't figure out how to make the Card class convert the string numbers over to integers and return the values so that I can use them in the CardTestDrive.
What am I doing wrong. This time I tried attaching the Java files rather that posting the code inside my question.
Create a virtual "War" card game. The way it needs to work is the player and the computer each get 5 cards. The player and the computer each lay a card down - whoever has the higher card wins that hand and takes both the cards. This continues until someone has all of the cards. That is the winner.
We need to
Create a class named Card. This class consists of the following:
1. A String instance variable named suit, which holds the suit of the card (Hearts, Diamonds, Clubs, Spades)
2. A String instance variable named number, which holds the number of the card (2,3,4,...9,10,Jack,Queen,King,Ace)
3. A constructor that contains the following;
1. A String array that holds all of the suits
2. A String array that holds all of the numbers
3. Generates a random number that randomly represents the suit and assigns that suit to the suit instance variable using the suits array (think about this - the random number is an int and the array is full of Strings)
4. Generates a random number that randomly represents the number and assigns that number to the number instance variable using the suits array
4. A method named getCard that takes the Sstring number and converts it to an integer so it can be used to compare values when the game begins. Your task is to figure out the logic for this method.
Create a class named CardTestDrive. This class is responsible for playing the game.
1. The player and the computer start off with 5 cards each.
2. Every time there is a "War", instntiate a player card object and a computer card object
3. Using the objects' instance variables and method, compare the two cards number values. If it is a tie, disregard that particular war.
4. Based upon who wins, update the number of cards each player has.
My can't figure out how to make the Card class convert the string numbers over to integers and return the values so that I can use them in the CardTestDrive.
What am I doing wrong. This time I tried attaching the Java files rather that posting the code inside my question.