Results 1 to 2 of 2
  1. #1
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

    Default Writing classes???

    Hey guys doing hw , wondering if this code completes the first step of this multi part problem ..Heres the first part
    22. (20 points) Deck of cards that use another class Card.
    (a) Create a class called Card that represents a standard playing card. Each card has a suit and a face value.

    And here's the code (Thanks for the response in advance:):))


    Java Code:
    public class Card{
    String suit;
    int faceValue;
    
    
    public Card (String s,int fV) {
    suit = s;
    faceValue = fV;
    }
    public String toString(){
    
    return ("Suit:" + suit + " " + "Face Value:" + faceValue);
    	}
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,252
    Rep Power
    19

    Default

    Comments and criticism:

    1. Learn how code should be formatted: Code Conventions for the Java(TM) Programming Language: Contents
    2. Instance fields should be private.
    3. Would you allow a program to change the suit or faceValue of a Card after it has been constructed? If not, the instance fields should be final.
    4. Later when you learn about documentation, you will come to know how the parameters to constructors and methods are documented. At this stage of your learning, suffice to say that giving meaningful identifiers (names) to parameters is at least, if not more, important than it is for fields and method-local variables, and more so when the types/classes) of the parameters are common types like String and int. Single or two letter parameter identifiers are common and acceptable where the type implies the usage e.g. catch (Exception e) or actionPerformed(ActionEvent ae).
    5. Your toString() doesn't cater to card values that aren't usually expressed as an int: Ace, Jack, Queen, King.

    db

Similar Threads

  1. Replies: 1
    Last Post: 02-27-2010, 01:29 AM
  2. Writing in XLS
    By selva.bics in forum Advanced Java
    Replies: 1
    Last Post: 11-09-2009, 09:09 AM
  3. Writing importable classes
    By Katsu in forum New To Java
    Replies: 6
    Last Post: 03-08-2009, 09:10 PM
  4. writing to gui
    By rob in forum New To Java
    Replies: 2
    Last Post: 02-13-2009, 10:55 PM
  5. Writing classes in graphics
    By CyberFrog in forum Java Applets
    Replies: 2
    Last Post: 04-05-2008, 05:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •