jeudi 30 juin 2016

Java homework - Creating and using enumerations

I have a little Java project that I was assigned where we're creating and using enumerations. The instructions for this portion of the project are:

  • In the Card class, modify the code so it uses the Suit enumeration as the type for the suit instance variable. (STUCK ON THIS STEP)
  • In the Main class, modify the displayCard method so it uses the Suit enumeration to check the suit of the card.
  • In the Main class, experiment by modifying the code that sets the suit and number for the Cart object. Note that you can’t set an illegal suit, but you can set an illegal number.
  • Run the application to make sure it works correctly.

I am not sure if it is the wording that is confusing me, or if its because there is not an example in the textbook that even remotely resembles this project, so it is throwing me off. I was able to do the initial setup leading up to these steps, but now I am stuck. Any help or guidance in the right direction is appreciated!

The code below is for the Suit enum, followed by the code for the Card class:

package murach.card;

public enum Suit {
	SPADES,
	HEARTS,
	DIAMONDS,
	CLUBS;
}

package murach.card;

public class Card {
    private int suit;
    private int number;
    
    public void setSuit(int suit) {
        this.suit = suit;
    }    
    
    public int getSuit() {
        return this.suit;
    }
    
    public void setNumber(int number) {
        this.number = number;
    }    
    
    public int getNumber() {
        return this.number;
    }
}

Aucun commentaire:

Enregistrer un commentaire