Write a program that takes user input describing a playing card in the following shorthand notation:
[FONT=Courier New]Notation Meaning A Ace 2 … 10 Card values J Jack Q Queen K King D Diamonds H Hearts S Spades C Clubs[/FONT]Your program should print the full description of the card. For example,
Enter the card notation:
4S Four of spadesso far i have this
public class Card
{
private String notation;
public Card (String not)
{
not = notation;
}
public String getDescription()
{
String c;
String number = notation.substring (0, 0);
String type = notation.substring(1);
if (number == "A")
c = "Ace of";
else if (number == "2")
c = "Two of";
else if (number == "3")
c = "Three of";
else if (number == "4")
c = "Four of";
else if (number == "5")
c = "Five of";
else if (number == "6")
c = "Six of";
else if (number == "7")
c = "Seven of";
else if (number == "8")
c = "Eight of";
else if (number == "9")
c = "Nine of";
else if (number == "10")
c = "Ten of";
else if (number == "J")
c = "Jack of";
else if (number == "Q")
c = "Queen of";
else if (number == "K")
c = "King of";
else if (type == "S")
c = "Spade";
else if (type == "H")
c = "Heart";
else if (type == "D")
c = "Diamond";
else if (type == "C")
c = "Club";
else
c = "unknown";
return c;
}
}
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());
}
}
i guess there's a problem with substring. can anyone help me out how to straight it up? i am not too familar with substring. I tried out textbook method but it won't work for some reason
Edited by Alexander, 03 November 2010 - 07:03 PM.
Added code formatting


Sign In
Create Account

Back to top









