Our assignment was to
"Write a program that takes user input describing a playing card in the following shorthand notation:
A = Ace
2 . . . 10 = Card Values
J = Jack
Q = Queen
K = King
D = Diamonds
H = Hearts
S = Spades
C = Clubs
Your program should print the full description of the card. For example,
Quote
Enter the card notation:
4S
Four of spades
4S
Four of spades
"
So, this is what I have for the Card Class
public class Card
{
private String rank;
private String suit;
public String card;
public String description;
public Card(int rank, String suits)
{
this.suit = "Diamonds";
this.suit = "Hearts";
this.suit = "Spades";
this.suit = "Clubs";
if (rank == 1)
{
this.rank = "Ace";
}
else if (rank == 11)
{
this.rank = "Jack";
}
else if (rank == 12)
{
this.rank = "Queen";
}
else if (rank == 13)
{
this.rank = "King";
}
else
{
this.rank = "" + rank;
}
}
public Card(String input) {
}
public String getSuit()
{
return suit;
}
public String getRank()
{
return rank;
}
public String toString() { return rank + " " + suit; }
public String getCard()
{
return suit + rank;
}
public String getDescription()
{
return suit + rank;
}
{
}
}
And this is the given tester class:
import java. util.Scanner;
/**
This is a test for the Card class, which outputs the full
description of a deck of cards.
*/
public class CardPrinter
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter the card notation:");
String input = in.nextLine();
Card card = new Card(input);
System.out.println(card.getDescription());
}
}
What am I doing wrong? I keep getting 'null' once running. I'm new to java so I apologize for any novice mistakes.
Thanks for your help.

New Topic/Question
Reply




MultiQuote



|