0% found this document useful (0 votes)
3 views1 page

Lab 7

The document describes the creation of a method called makeDeck that generates a fully populated array of Card objects. It includes the definition of a Card class with attributes for rank and suit, along with methods to retrieve these attributes and a toString method for representation. The makeDeck method initializes an array of 52 cards by iterating through suits and ranks to populate the deck accordingly.

Uploaded by

2cdg5bbkvm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Lab 7

The document describes the creation of a method called makeDeck that generates a fully populated array of Card objects. It includes the definition of a Card class with attributes for rank and suit, along with methods to retrieve these attributes and a toString method for representation. The makeDeck method initializes an array of 52 cards by iterating through suits and ranks to populate the deck accordingly.

Uploaded by

2cdg5bbkvm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Encapsulate the deck-building code from Section 12.

6 in a method called makeDeck that takes


no parameters and returns a fully populated array of Cards.

In order for your code to work, you need to build a class called Card. Use the code we have
learned in this class.

package homeWork:

public class Cardi {


int rank;
int sult;
public Card1(int rank, int suit) {
this.rank = rank;
thIs.suit = SUlt:
}
public int getRank() {
return rank;
}
public int getSuit () {
recurn suit,
}
public String toString() {
return rank + " of + suit;
}
Card1[] makeDeck() &
Card1 [] deck = new Card1[52];
int count = 0;
for (int suit = 0; suit <= 3: suit++) ≤ {
for (int rank = 1: rank <= 13; rank++) {
deck[count] = new Card1(rank, suit);
count++:
}
}
return deck;
}
}

You might also like