My question today is, how can I assign values for my state variables/methods, in order to compare values to determine the winner?
Also, how do I direct the values to "Jack" and "Jill" (player p1 and p2)?
Should I use if-else statements?
And last question: why does my console print "null" for my getScore, getcardSuit, getcardValue, etc??
(I will give you my console printout after all of this)
Here is my code for my "player class", and my "tester" project is below this code (to test my player class):
public class player {
// The two players are going to enter:
String p1[] = {"Jack", "h", "k"};
String p2[] = {"Jill", "d", "9"};
//Setting up values
String Jack = "Jack";
String Jill = "Jill";
String h = " Hearts ";
String d = " Diamonds ";
String k = " King ";
int val = 9;
// Score
public int score = 0; // State variable score, set equal to 0
// Player name - Jack, Jill
public player(String Jack, String h, String k) {
// TODO Auto-generated constructor stub
}
public String playerName(String player)
{
player = "Jack";
player = "Jill";
return player;
}
// Card suit
public String cardSuit(String getcardSuit)
{
return cardSuit;
}
// Card Value for player 1
public String getCardValue()
{
return cardValue;
}
public String getScore(String score)
{
return score;
}
public String player;
public String playerName;
public String cardSuit;
public String cardValue;
public double getScore;
public String getCardSuit()
{
return cardSuit;
}
public int getScore() {
return 0;
}
}
Here is my "Tester", to test my "player class":
public class Tester {
public static void main(String[] args) {
// Create an object for player 1
player p1 = new player("Jack", "h", "k");
// Create an object for player 2
player p2 = new player("Jill", "d", "9");
// Use p1 object and methods getCardSuit and getCardValue to report p1's card
System.out.println(p1.playerName+"'s card is a "+p1.getCardValue()+" of "+p1.getCardSuit()+".");
// Should print:
// Jack's card is a King of Hearts.
// Use p2 object and methods getCardSuit and getCardValue to report p2's card
System.out.println(p2.playerName+"'s card is a "+p2.getCardValue()+" of "+p2.getCardSuit()+".");
// Should print:
// Jill's card is a 9 of Diamonds.
// Compare player's scores to determine winner
if(p1.getScore()>p2.getScore())
System.out.println(p1.playerName+" is the winner!");
else if (p1.getScore()<p2.getScore());
System.out.println(p2.playerName+" is the winner!");
// Should print:
// "Jack is the winner!"
}
}
CONSOLE:
null's card is a null of null.
null's card is a null of null.
null is the winner!
how can I fix this "null" stuff and actually have their values printed??
Thanks so much, in advance! :)
I'll start by answering the question you asked:
The values are null because they were never initialized. Your constructor for the player class:
public player(String Jack, String h, String k) {
// does absolutely nothing with the values.
}
does nothing. This means you created a new player player1 and a new player player2 but didn't actually use the values to do anything at all.
player p1 = new player("Jack", "h", "k");
calls the constructor, sends in values and the values are ignored. An instance of player1 is created and absolutely nothing is done with the information. You, therefore, cannot compare the values to each other since they have not been initialized.
Other considerations
When you make a class, in object oriented programming you should think in an OO sort of way.
The player class can/should have a String name; variable and you can then create a Player object and pass the name, exactly like you did. The difference is in your constructor:
//Setting up values
String name;
String suit;
String value;
public player(String name, String suit, String value) {
this.name = name;
this.suit = suit;
this.value = value;
}
This technique creates a player1 object with a name, a suit and a value. Now the values within this object can be compared to equal values in another player object if you so choose.
So I tried to clean up your Player class a bit:
public class Player
{
// The two players are going to enter:
String p1[] = {"Jack", "h", "k"};
String p2[] = {"Jill", "d", "9"};
//Setting up values
String jack = "Jack";
String jill = "Jill";
String h = " Hearts ";
String d = " Diamonds ";
String k = " King ";
int val = 9;
// Score
public int score = 0; // State variable score, set equal to 0
// Player name - Jack, Jill
public Player(String jack, String h, String k)
{
this.jack = jack;
this.h = h;
this.k = k;
}
public String playerName(String player)
{
// not sure what this is doing?
// this first line does nothing at all
// because player gets reassigned to "Jill"
player = "Jack";
player = "Jill";
return player;
}
// Card suit
public String cardSuit(String getcardSuit)
{
return cardSuit;
}
// Card Value for player 1
public String getCardValue()
{
return cardValue;
}
public String getScore(String score)
{
return score;
}
public String player;
public String playerName;
public String cardSuit;
public String cardValue;
public double getScore;
public String getCardSuit()
{
return cardSuit;
}
public int getScore()
{
return 0;
}
}
There are a couple of conventions you should start using. Class names should start with an uppercase letter. Variables and stuff like that should all have lower case letters (unless it is a static).
Related
I'm trying to make a card dealer program and I'm using a scanner to input manually how many number of players there are. But, I'm kind of stuck on how to divide/deal the cards to the specified amount of players.
The result that I'm aiming for is kinda like this
Example: dealing it to 4 players
Spade-2 1stplayer
Queen-Heart 2nd player
Club-5 3rd player
Club-9 4th player
Diamond-7 1st player
Spade-Jack 2nd player
.... and so on until it deals all 52 cards to 4 players
This is the current code that I wrote while looking for tutorials on how to shuffle a deck of cards.
import java.util.Scanner;
public class main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Please Input how many players there are");
int player = sc.nextInt();
if (player > 0) {
String[] type = {"S-", "H-", "D-", "C-"} ;
String[] rank = {"A ", "2 ", "3 ", "4 ", "5 ", "6 ", "7 ", "8 ", "9 ", "10 ", "J ", "Q ", "K "};
String[] cset = new String[52];
for (int i = 0; i < cset.length; i++) {
cset[i] = type[i/13] + rank[i%13];
}
for (int i = 0; i < cset.length; i++) {
int index = (int) (Math.random() * cset.length);
String temp = cset[i];
cset[i] = cset[index];
cset[index] = temp;
}
for (String u: cset) {
System.out.println(u);
}
} else {
System.out.println("Please input a correct number of player/s");
}
}
}
Can someone please help me?
Sorry if my explanation is confusing
As noticed by #MarsAtomic and #Nexevis in the comments, you can shuffle an ArrayList using static method Collections.shuffle():
Suit.java
public enum Suit {
CLUBS('\u2663'), DIAMONDS('\u2666'), HEARTS('\u2764'), SPADES('\u2660');
private final char symbol;
private Suit(char symbol) {
this.symbol = symbol;
}
public final char getSymbol() {
return symbol;
}
}
Card.java
public static class Card {
private final Suit suit;
private final int value;
private transient final String name;
public Card(Suit suit, int value) {
this.suit = suit;
this.value = value;
this.name = createName(suit, value);
}
public final Suit getSuit() {
return suit;
}
public final int getValue() {
return value;
}
public final String getName() {
return name;
}
#Override
public String toString() {
return name;
}
private static String createName(Suit suit, int value) {
char symbol = suit.getSymbol();
switch(value) {
case 1:
return "A" + symbol;
case 11:
return "J" + symbol;
case 12:
return "Q" + symbol;
case 13:
return "K" + symbol;
default:
return Integer.toString(value) + symbol;
}
}
}
Methods to deal cards:
public static List<List<Card>> deal(int players, int playerCards) {
List<Card> cards = Stream.of(Suit.values())
.flatMap(suit -> IntStream.range(1, 14)
.mapToObj(value -> new Card(suit, value)))
.collect(Collectors.toList());
Collections.shuffle(cards);
return IntStream.range(0, players)
.map(i -> i * playerCards)
.mapToObj(index -> cards.subList(index, index + playerCards))
.collect(Collectors.toList());
}
public static List<List<Card>> dealAll(int players) {
return deal(players, Math.round(52f / players));
}
Then you can do:
List<List<Card>> cards = dealAll(4); // or deal(4, 13) if each player has a specific number of cards
cards.forEach(System.out::println);
Output:
[5♣, 4♣, 9♣, 7♣, 5❤, 6♠, 3♠, K♦, 4♦, 6♣, Q♦, 9♦, J♦]
[Q♣, 2♦, 9♠, Q❤, 7♦, 10♣, 9❤, 5♠, 2♣, 10❤, 5♦, A❤, 8❤]
[2♠, 8♠, 8♣, 4♠, 10♦, 3♣, 2❤, 3♦, K♣, 7♠, A♣, 3❤, J❤]
[7❤, J♠, 4❤, Q♠, 6♦, 10♠, A♦, K❤, A♠, J♣, 8♦, K♠, 6❤]
I am learning JAVA OOP, I have to compare the age between 2 objects:
In java Procedural, I will have done:
public static int calculateDifferenceAge(int agePlayer1, int agePlayer2){
int differenceAge = agePlayer1 - agePlayer2;
if(differenceAge < 0){
differenceAge = -differenceAge;
}
return differenceAge;
}
Then
public static void displayDifferenceAge(String namePlayer1, String namePlayer2, int agePlayer1, int agePlayer2){
System.out.println("Age difference between " + namePlayer1 + " and " + namePlayer2 + " is of" + calculateDifferenceAge(agePlayer1, agePlayer2) + " year(s).");
}
}
I don't understand how to create my calculateDifferenceAge() method in OOP ?
In my main file I have this:
List<Player> players = new ArrayList <Player>();
players.add(new Player("Eric", 31, true));
players.add(new Player("Juliette", 27, false));
I am stuck into my 2 methods:
How to subtract the age of 2 objects?
public static int calculateAgeDifference(List <Player> players){
Player differenceAge = (players.get(0) - players.get(1));
return differenceAge;
}
public static void displayCalculateAgeDifference(List <Player> players){
System.out.println(calculateAgeDifference().age);
}
Class Player
public class Player {
public String name;
public int age;
public boolean sex;
public Player(String name, int age, boolean sex){
this.name = name;
this.age = age;
this.sex = sex;
}
you're only missing a little step in your code. The steps to extract the ages of the list should be:
1.- Extract the object from the list
2.- Extract the age of that object (or player, in this case)
3.- Substract the ages
There's some ways to do it, but I would do it this way:
public static int calculateAgeDifference(List<Player> players) {
int age1= players.get(0).age;
int age2= players.get(1).age;
int differenceAge = age1 - age2;
if(differenceAge < 0){
differenceAge = -differenceAge;
}
return differenceAge;
}
I hope that helps. What i've done there is extract the objects player from the list: players.get(0) extracts the first object inside the list, which is a Player. Now that I have a player and it has an age variable i have to extract it with player.age. I collapsed those steps, if you have any questions I can explain you further
Display method:
public static int displayCalculateAgeDifference (List<Player> players){
String name1= players.get(0).name;
String name2= players.get(1).name;
//as you know this method return the difference in a number form
int difference= calculateAgeDifference(players);
System.out.println("Age difference between " + name1 + " and " + name2 + " is of" + difference + " year(s).");
}
Let's start with a class Player. Let's give it a name and an age, and a calculateAgeDifference method. It should look something like,
public class Player {
private int age;
private String name;
public Player(String name, int age) {
this.name = name;
this.age = age;
}
public int calculateAgeDifference(Player player2) {
return Math.abs(this.age - player2.age);
}
}
Then you can call it like
Player a = new Player("Eric", 40);
Player b = new Player("Sally", 51);
System.out.println(a.calculateAgeDifference(b));
You must have a similar Player class. Yours appears to also have a boolean field. It isn't clear why. So I can't speak to that.
Why did your method interface change from two parameters to a list? You can still pass two instances of the object. You can still return the integer age value from the method, no need to create a Frankenstein's Player instance only to hold the age.
I am assuming your Player class has a method getAge() to extract the age value which was passed in in the constructor:
public static int calcAgeDiff(final Player player1, final Player player2) {
int age1 = player1.getAge();
int age2 = player2.getAge();
return Math.abs(age2 - age1);
}
Alternatively, you can add an instance method to your Player class itself to calculate the age difference to a different player:
public class Player {
// fields
// constructor
// getters
public int ageDiffTo(final Player otherPlayer) {
return Math.abs(this.age - otherPlayer.age); // <- a class can always access its private fields, even of other instances
}
}
then call as player1.ageDiffTo(player2)
I got a list of players with a skill from 0-100 and a list of teams which have all their own members list.
Now I want to put the players to the teams so that teams mostly got the same size (+-1 difference is ok) and the sums of the skills should be as close at possible.
My current solution is a simple voting algorithm (teams vote players in circle, an take the next best player):
public class Teamgenerator {
public void calcTeams(){
List<Team> teams = new ArrayList<>();
teams.add(new Team("Team 1"));
teams.add(new Team("Team 2"));
List<Player> players = new ArrayList<>();
players.add(new Player("Player 1",25));
players.add(new Player("Player 2",50));
players.add(new Player("Player 3",50));
players.add(new Player("Player 4",75));
int nextTeam = 0;
while (players.size() > 0) {
int bestPlayer = findBestPlayerIndex(players);
teams.get(nextTeam).players.add(players.get(bestPlayer));
players.remove(bestPlayer);
if (nextTeam < teams.size() - 1) nextTeam++;
else nextTeam = 0;
}
for(Team t:teams){
System.out.println(t.getName()+":");
for(Player p:t.players)
System.out.println(p.getName()+", Skill "+p.getSkill());
}
}
private int findBestPlayerIndex(List<Player> players) {
//In my real programm i have to pick the skill of a more complex player object from a DB,
//depending on a specific competition, which causes i really need this index finding
int index = -1;
int highestSkill=-1;
for (int i = 0; i < players.size(); i++) {
if (players.get(i).getSkill() > highestSkill) {
highestSkill = players.get(i).getSkill();
index = i;
}
}
return index;
}
}
public class Team {
private String name;
public ArrayList<Player> players=new ArrayList<>();
public Team(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class Player {
private String name;
private int skill=50; //From 0-100
public Player(String name, int skill) {
this.name = name;
this.skill = skill;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSkill() {
return skill;
}
public void setSkill(int skill) {
this.skill = skill;
}
}
The problem is that gives not the most even teams, console output is:
Team 1:
Player 4, Skill 75;
Player 3, Skill 50
Team 2:
Player 2, Skill 50;
Player 1, Skill 25
But it would be more fair if the teams are 4+1 and player 3+2.
You got any idea of a more fair algorithm? Thanks for help!
As seen on YouTube - The Fairest Sharing Sequence Ever - Standup Maths the Thue-Morse Sequence is probably your best bet for minimising first turn advantage.
Wikipedia:
In mathematics, the Thue–Morse sequence, or Prouhet–Thue–Morse sequence, is the binary sequence (an infinite sequence of 0s and 1s) obtained by starting with 0 and successively appending the Boolean complement of the sequence obtained thus far. The first few steps of this procedure yield the strings 0 then 01, 0110, 01101001, 0110100110010110, and so on, which are prefixes of the Thue–Morse sequence. ...
Intro Computer Science - Princeton
//Copyright © 2000–2016, Robert Sedgewick and Kevin Wayne.
public class ThueMorse {
public static void main(String[] args) {
int n = Integer.parseInt(args[0]);
String thue = "0";
String morse = "1";
for (int i = 1; i <= n; i++) {
String t = thue; // save away values
String m = morse;
thue += m;
morse += t;
}
System.out.println(thue);
}
}
Porting from a Python answer, to get a SO copyright approved version:
public static int whoseTurn(int turnCount){
return Integer.bitCount(turnCount) % 2;
}
Using this turn order, with a sorted list based on skill level should give fairer teams, and meet your constraint of being within +-1 member.
Verified against the online encyclopedia of integer sequences (A010060) by generating the first 105 digits.
import java.util.stream.IntStream;
public class NodeStack {
public static int whoseTurn(int turnCount){
return Integer.bitCount(turnCount) % 2;
}
public static void main(String[] args) {
System.out.print("OEIS: ");
IntStream.range(0,105).map(NodeStack::whoseTurn).forEach(i->System.out.print(i+", "));
String result = IntStream.range(0,105).map(NodeStack::whoseTurn).collect(StringBuilder::new,(sb,i)->sb.append(i), StringBuilder::append).toString();
System.out.println();
IntStream.range(1,105).forEach(
(i)-> System.out.println(i+"# "+result.substring(0,i)+ " : " +diff(result.substring(0,i)))
);
}
public static int diff(String s){
int zero = 0;
int one = 0;
for (char c:s.toCharArray()){
if (c=='0')zero++;
if (c=='1')one++;
}
return zero-one;
}
}
So I have a bunch of classes used for an animal hospital. My superClass, Pet, has four constants, MALE, FEMALE, SPAYED, NEUTERED, that are set to numbers. When a data file is read in, in my AnimalHospitalClass, it is supposed to set the gender to a number, go back to the Pet class compare the "sexId" to the constant, and then return the gender. The issue Im having is not logical but technical. For some reason my setter is (setSex(sexID)) is getting the number that my gender is set to, but when I try to make the if statements in my getter to compare the numbers and return the gender, the sexID ( which is a variable in the Pet class) is set back to 0, instead of what I set it to.
heres my Pet Class:
public class Pet{
private String petName;
private String ownerName;
private String color;
protected int sexID;
public static final int MALE = 1;
public static final int FEMALE = 2;
public static final int SPAYED = 3;
public static final int NEUTERED = 4;
public Pet(String petName, String ownerName, String color){
this.petName = petName;
this.ownerName = ownerName;
this.color = color;
}
// getters
public String getPetName(){
return petName;
}
public String getOwnerName(){
return ownerName;
}
public String getColor(){
return color;
}
public String getSex(){
/* this is where I am having issues, instead of sexID being set to what
it is in the setter, it is set back to 0*/
System.out.println("SEXID: " + sexID); // will print 0
if(sexID == MALE){
return("male " );
}
else if(sexID == FEMALE){
return("female");
}
else if(sexID == SPAYED){
return("spayed");
}
else if(sexID == NEUTERED){
return("neutered");
}
else{ // will print else only since sexID is equal to 0
return("Not Available. " + sexID);
// in case there is no gender in the file
}
}
public void setSex(int sexID){
this.sexID = sexID;
System.out.println("SEX: " + sexID); // this will print the correct
// sexID that was set in the other class
}
public String toString(){
return(petName + "owned by " + ownerName
+ "\nColor: " + color
+"\nSex: " + getSex() );
}
}
here is my Animal hospital class (only one method since it is large):
import java.util.*;
import java.io.*;
public class AnimalHospital{
Scanner input;
private String pName;
private String pName2;
private String oName;
private String color ;
private String specialType; // store hair length for cats, size for dogs
private String gender;
private String type; // finds CAT, DOG, BIRD
public AnimalHospital(String inputFile)throws FileNotFoundException{
input = new Scanner(new File(inputFile));
}
public void printPetInfoByOwner(String name){
Pet pet = new Pet(pName,oName,color);
while(input.hasNext()){
String type = input.next(); // finds Cat, Dog, Bird
pName = input.next(); // gets pet name
oName = input.next(); // gets owner name
color = input.next();
gender = input.next();
if(gender.equals("male")){ // this is where I set the gender
int male = 1; // to a number so I can compare
pet.setSex(male);
}
if(gender.equals("female")){
int female = 2;
pet.setSex(female);
}
if(gender.equals("spayed")){
int spayed = 3;
pet.setSex(spayed);
}
if(gender.equals("neutered")){
int neutered = 4;
pet.setSex(neutered);
}
if(!(type.equals("BIRD"))){
specialType = input.next(); // since Bird does not have a special type
}
if(type.equals("CAT") && oName.equals(name)){
Cat cat = new Cat(pName, oName, color, specialType);
System.out.println(cat.toString());
break;
}
if(type.equals("DOG") && oName.equals(name)){
Dog d = new Dog(pName, oName, color, specialType);
System.out.println(d.toString());
break;
}
if(type.equals("BIRD") && oName.equals(name)){
Bird b = new Bird(pName, oName, color);
System.out.println(b.toString());
break;
}
}
}
here is an example output:
CAT: Busker owned by Samantha
Color: Black
Sex: Not Available. 0 // reads sex as 0 should be 2, and female
Hair: short
AnimalHospital#55f96302 // also how do I get rid of this?
Note:
This is an assignment, and I understand if you don't want to give me the answer, any hints would be helpful, but I've thought about this for days and can't figure it out.
thanks!
You're setting the sex on the pet variable, of type Pet. Then you create a Cat, Bird or Dog, never set its sex, and print it. So, since you never set the sex of the Cat, Bird or Dog, it's 0.
i seem to be having a problem with my deck class iterating through the Suits array.
Card class:
//David Diienno
//Lab 01
import java.util.Arrays;
public class Card {
private String m_rank; // card rank: a number between 2 and 10, or Jack, Queen, King or Ace
private char m_suit; // card suit: S, C, H, or D (spades, clubs, hearts, or diamonds)
// Helpful supporting structures
private static String [] Ranks = {"2","3","4","5","6","7","8","9","10", "Jack", "Queen", "King", "Ace"};
private static char [] Suits = {'C','H','D','S'};
// Default constructor: sets card rank to 2 and card suit to H
public Card(){
//setting default card to a 2 of hearts
m_rank = Ranks[0];
m_suit = Suits[1];
}
// Accessors and Mutators
public Card(String Rank, char suit){
if(isValidRank(Rank) == true){
m_rank = Rank;
}
if(isValidSuit(suit) == true){
m_suit = suit;
}
}
public String getRank() {
System.out.println(m_rank);
return m_rank;
}
public char getSuit() {
System.out.println(this.suitToString());
return m_suit;
}
public void setRank(String rank) {
// Make sure to validate provided input
if (isValidRank(rank) == true){
m_rank = rank;
}
else{
System.out.println("The rank you entered is invalid");
}
}
public void setSuit(char suit) {
// Make sure to validate provided input
if(isValidSuit(suit) == true){
m_suit = suit;
}
else{
System.out.println("The suit you entered is invalid");
}
}
// Method toString – returns string representation of the card that looks as follows:
// 2 of Hearts, 3 of Spades, Jack of Diamonds, etc.
// Requirement: you must use switch statement to convert character to string.
//
// Hint: card’s rank is already a string. Therefore you only need to convert card suit into
// a string that reads “Clubs”, “Spades”, “Hearts” or “Diamond s”
public String suitToString(){
switch(m_suit){
case 'c': return "Clubs";
case 'h': return "Hearts";
case 'd': return "Diamonds";
case 's': return "Spades";
default: return "Hearts";
}
}
public String toString() {
String data = "You have a " + m_rank + " of " + this.suitToString();
return data;
}
// Supporting static methods
// Returns an array of possible card ranks
public static String [ ] getPossibleRanks() {
//System.out.println(Arrays.toString(Ranks));
for(int i = 0; i < Card.Ranks.length; i ++){
System.out.println(Ranks[i]);
}
return Ranks;
}
// Returns an array of possible card suits
public static char [ ] getPossibleSuits() {
for(int i = 0; i < Card.Suits.length;i++){
System.out.println(Suits[i]);
}
return Suits;
}
public boolean isValidRank (String r){
for(int i = 0; i < Card.Ranks.length; i++ ){
if(Card.Ranks[i].equals( r)){
return true;
}
}
return false;
}
public boolean isValidSuit (char s){
for (int i = 0; i < Card.Suits.length; i++){
if(Card.Suits[i] == s){
return true ;
}
}
return false;
}
}
Deck class :
import java.util.*;
public class DeckOfCards extends Card {
private ArrayList <Card> deck;
private Card card;
private String [] Ranks = super.getPossibleRanks();
private char [] Suits = super.getPossibleSuits();
// public void resetDeckOfCards() {
public DeckOfCards()
deck = new ArrayList<Card>();
for(int s = 0; s < Suits.length; s++)
{
for(int r = 0; r < Ranks.length; r++){
card = new Card(Ranks[r],Suits[s]);
deck.add(card);
}
}
}
public void display(){
System.out.println(deck);
}
//public Card getCard() { /* ... */ }
//Remove a random card from the Array List of cards and return its value from this method Notes:
//1. Ensure that there is at least one card in the ArrayList of Cards
//2. If there are no more cards left in the ArrayList of Cards, reset the Deck of Cards
//3. Use class Random to create a random number which will be an index into ArrayList of Cards
//4. Remove and return card stored in the ArrayList of Cards in the randomly created index
// Return an ArrayList of specified size (i.e. returned cards are being removed from the deck). //
// Notes:
// 1. Use method getCard() to retrieve a single card
// 2. Validate the value of size passed into this method and return null if size is invalid
//public ArrayList<Card> getHand(int size) { /* ... */ }
}
Why when i display my array list it doesn't iterate through the suits but it does through the ranks, i still get 52 cards but all with same suit.
So the problem appears to be that your Suits array has capital letters, but your suitToString method is using a switch statement where lower case letters are used. Since the default case is Hearts, I bet all your cards are hearts.