JAVA Poker Simulator Project! Help :)

Here is what I found. You're getting the error because your line:
SimpleDeck gameDeck[] = new SimpleDeck(); is creating an array that points to a single object, instead of pointing to an array. Here is my suggestion for the code, without completely understanding your code(include more comments). It eliminates the error, but I'm not quite sure about the inner workings of your program so I can't make it work, lol... So here goes:
Code:
public class Game
{
public static void main(String[] args)
{
SimpleDeck gameDeck[] = new SimpleDeck[5]; // allocate memory here, don't call SimpleDeck()'s constructor yet
String[] hand = new String[5];
System.out.println("Welcome to Video Poker");
System.out.println("Your hand");
int j = 0;
for (int i = 0; i < 5; i++)
{
 gameDeck[i] = new SimpleDeck(); // now we initialize the particular gameDeck to a new object of the simpledeck class
hand[i] = gameDeck[j].toString(); // because hand[i] is looking for a string
j++;
}
}
}

I didn't modify the other files, I used your toString() method because it was looking for a string, but when I output i'm getting the object name, and not the default toString method, have you considered creating an inheritence relationship between simpleDeck and simpleCard?
Code:
public class simpleDeck extends SimpleCard {
  simpleDeck() {
   super("","");
  }
  simpleDeck(String rank, String Suit) {
  super(rank, Suit);
 }
}
 
The second piece of code I dont understand it whats super. Let me comment my code and ill post it.
 
a call to super() means to call the constructor of the super class.
For example:
Lets say you have two classes.
Animal Class,
Bear Class.

Animal class:
Code:
public class Animal {
  private String animalName; // private class-wide instance variable for storing the animal's name
  public Animal(String name) {
    setName(name);
  } // end 1 argument constructor for Animal class
  public Animal() {
  } // end default no-argument constructor
 
  public void setName(String theName) {
    animalName = theName;
  } // end method setName
  public String getName() {
    return animalName;
  } // end method getName
} // end class Animal
Bear class:
Code:
public class Bear extends Animal {
 private String bearName; // the name of our bear
 private int bearWeight;
 public Bear(String myBearName) {
  super(myBearName); // make a call to the super-class' 1 argument constructor that takes a string
 } // end 1 argument constructor
 public Bear() {
  super(); // call the default no-argument constructor
 } // end default no-argument constructor
 public void setWeight(int weight) {
  // here we are overriding the super class' setWeight method because while a bear IS an animal, it weighs more, so we want to change the method
  bearWeight = weight *2;
 } // end method setWeight
 public int getWeight() {
  return bearWeight;
 } // end method getWeight
} // end class Bear
Zoo class:
Code:
// This is a zoo class where we have all of our animals
public class zoo {
 public static void main(String args[]) {
  Animal a1 = new Animal("Cat");
  a1.setWeight(4);
  Animal a2 = new Animal("Dog");
  a2.setWeight(25);
  // now we get into some polymorphism
  Animal b1 = new Bear("Big Bear");
  b1.setWeight(105);
  System.out.printf("%s\t%s\t\n%s\t%s\n\n%s\t%s\t\n%s\t%s\n\n%s\t%s\t\n%s\t%s\n\n", "Animal 1 is a:",a1.getName(),"It weighs:",a1.getWeight() + " lbs.","Animal 2 is a:",a2.getName(),"It weighs:",a2.getWeight() + " lbs.","Animal 3 is a:",b1.getName(),"It weighs:",b1.getWeight() + " lbs.");
 } // end method main
} // end class zoo
As you can see, the bear has a unique relationship to animal, because when you put the keyword "extends" next to your class header the class you are writing, "inherits" all of the methods of the class you are extending from(or the "super" class). so, when you say: super();, you're making a call to the super class's constructor
 
Back
Top Bottom