How can I get all of the cards to print? So far this is what I have but I\'m stu
ID: 3534607 • Letter: H
Question
How can I get all of the cards to print? So far this is what I have but I'm stuck
public class cardTest
{
//This is the class to test the card class
public void main(String[] args) {
System.out.println(getCard());//I get an error here
}
}
public class card
{
private int[][] deck;
private String[] suit = {"Spades", "Hearts", "Clubs", "Diamonds"};
private int trump;
private String theCard;
public card(int t)
{
trump = t;
t = 2;
if(trump == 0){
int[][] table = {{6, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 5},
{5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4},
{5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4},
{5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4}};
deck = table;
}
else if(trump == 1){
int[][] table ={{5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4},
{6, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 5},
{5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4},
{5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4}};
deck = table;
}
else if(trump == 2){
int[][] table ={{5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4},
{5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4},
{6, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 5},
{5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4}};
deck = table;
}
else {
int[][] table ={{5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4},
{5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4},
{5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4},
{6, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 5}};
deck = table;
}
}
public String getTrump(){
return suit[trump];
}
public String getCard(){
for(int i = 0; i < deck.length; i++){
for(int j = 0; j < deck[i].length; j++){
switch (deck[i][j]){
case 0: theCard = "Ace of ";
case 1: theCard = "Two of ";
case 2: theCard = "Three of ";
case 3: theCard = "Four of ";
case 4: theCard = "Five of ";
case 5: theCard = "Six of ";
case 6: theCard = "Seven of ";
case 7: theCard = "Eight of ";
case 8: theCard = "Nine of ";
case 9: theCard = "Ten of ";
case 10: theCard = "Jack of ";
case 11: theCard = "Queen of ";
case 12: theCard = "King of ";
}
}
}
return theCard;
}
}
Explanation / Answer
public class Card
{
private int rank;
private int suit;
public String tostring(Card card1)
{
String result = "";
if (rank == 1) {
result = "Ace";
}
if (rank == 2) {
result = "Two";
}
if (rank == 3) {
result = "Three";
}
if (rank == 4) {
result = "Four";
}
if (rank == 5) {
result = "Five";
}
if (rank == 6) {
result = "Six";
}
if (rank == 7) {
result = "Seven";
}
if (rank == 8) {
result = "Eight";
}
if (rank == 9) {
result = "Nine";
}
if (rank == 10) {
result = "Ten";
}
if (rank == 11) {
result = "Jack";
}
if (rank == 12) {
result = "Queen";
}
if (rank == 13) {
result = "King";
}
if (suit == 1) {
result = result + " of Clubs ";
}
if (suit == 2) {
result = result + " of Diamonds ";
}
if (suit == 3) {
result = result + " of Hearts ";
}
if (suit == 4) {
result = result + " of Spades ";
}
return result;
}
public Card(int rank, int suit)
{
this.rank = rank;
this.suit = suit;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.