Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: parsecard method

  1. #1
    Join Date
    Mar 2013
    Thanked 0 Times in 0 Posts

    Default parsecard method

    I don't know where to begin in writing this method. Any help would be great!

    Write a class method for the Card class called parseCard that takes a String and returns
    the corresponding card. You can assume that the String contains the name of a card in a
    valid format, as if it had been produced by printCard.
    In other words, the string will contain a single space between the rank and the word ``of,''
    and between the word ``of'' and the suit. If the string does not contain a legal card name, the
    method should return a null object.

  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Thanked 206 Times in 182 Posts

    Default Re: parsecard method

    This isn't really a collections or generics problem (though it might have arisen in connection with a generified pack of cards...). It seems like a String question.

    Have a look at the String methods and see what's useful. Basically you want to examine the first character, the next 4 (which should be " of "), the next ? for the suit, and finally the remainder (there shouildn't be any). Return null as soon as you get "bad" I'm input, otherwise construct and return the Card.

Similar Threads

  1. Replies: 1
    Last Post: January 23rd, 2013, 07:29 AM
  2. [SOLVED] How to create a Java generic method, similar to a C++ template method?
    By Sharmeen in forum Object Oriented Programming
    Replies: 3
    Last Post: October 18th, 2012, 02:33 AM
  3. Replies: 3
    Last Post: October 31st, 2011, 12:42 AM
  4. How do I call a method from the main method?
    By JavaStudent1988 in forum Java Theory & Questions
    Replies: 5
    Last Post: October 19th, 2011, 08:37 PM
  5. Can i call init() method in destroy method.?
    By muralidhar in forum Java Servlet
    Replies: 1
    Last Post: October 22nd, 2010, 11:18 AM