Results 1 to 3 of 3
  1. #1
    elvis0288 is offline Member
    Join Date
    Jan 2012
    Posts
    21
    Rep Power
    0

    Default i am new and this is probably an easy question help please

    hi my problem is that i need my program to show (suit: 1, value: 4) but instead of that i am getting 0 and 0 i am new in java please help this is my code...



    public class Card
    {
    private int suit;
    private int value;

    public Card(int suit, int value){

    }

    public int getSuit(){
    return suit;
    }

    public int getValue(){
    return value;
    }

    public static void main(String[] args)
    {
    Card c = new Card(1, 4);
    System.out.println("suit:" + c.getSuit() + " value:" + c.getValue() + ")");
    }


    public String toString()
    {
    return "(suit:" + suit + " value:" + value + ")";
    }

    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: i am new and this is probably an easy question help please

    Your problem is here:

    Java Code:
    public Card(int suit, int value){
      // there's no code in here!
    }
    Your constructor is getting parameters but is doing nothing with them. Perhaps you want to use these parameters to update your class fields.

  3. #3
    Join Date
    Sep 2011
    Location
    Mumbai, India
    Posts
    35
    Rep Power
    0

    Default Re: i am new and this is probably an easy question help please

    You haven't initialized your instance variables i.e. suit and value in the constructor. .
    Java Code:
    public Card(int suit, int value){
    
    }
    So please do them

Similar Threads

  1. Easy solvable question.
    By xneonx in forum New To Java
    Replies: 5
    Last Post: 10-22-2010, 02:35 PM
  2. Quick easy question
    By jigglywiggly in forum New To Java
    Replies: 8
    Last Post: 01-04-2010, 04:34 PM
  3. New to Java and have an easy question
    By JBOY08 in forum New To Java
    Replies: 1
    Last Post: 11-19-2008, 08:40 PM
  4. quick easy question
    By jmHoekst in forum New To Java
    Replies: 1
    Last Post: 06-19-2008, 04:28 PM
  5. Easy question
    By JavaNoob in forum New To Java
    Replies: 10
    Last Post: 08-03-2007, 11:28 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
  •