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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 3 of 3

Thread: I need an advice

  1. #1
    Member
    Join Date
    Nov 2013
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I need an advice

    Hi everybody ,
    can you guide me please what am i missing?
    so i create a class called Lecturer ,this is part of the code(of the class)
    private String name;
    	private int numOfTimesPenFalls;
    	private String favoriteIceCream;
     
    	public Lecturer(String name,int NumOfTimesPenFalls,String FavoriteIceCream){
    		this.name=name;
    		setNumOfTimesPenFalls(numOfTimesPenFalls);
    		setFavoriteIceCream(favoriteIceCream);}
     
    public String toString(){
    		return "Name: "+name+" number of times pen falls: "+numOfTimesPenFalls+" Favorite iceCream: "+favoriteIceCream;}

    and in the class i also create set's and get's methods for penFalls and IceCream..

    in the main i create an object = Lecturer lec1=new Lecturer("John",4,"Vanila");
    and then i check if toString method word correct = System.out.println(lec1.toString());

    and here is my problem ,the output is: Name: John number of times pen falls: 0 Favorite iceCream: null

    My Question is why :number of times pen falls is '0' and not 4 ? and wht iceCream is 'null'.
    what did i do wrong/miss?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: I need an advice

    what did i do wrong/miss?
    0 and null look like the default values for the variables. Make sure the constructor is setting the values of the variables that are being used by the toString() method.
    The set methods aren't posted so I can't see what they are doing. The name variable is getting the value: "John" ok.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Nov 2013
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need an advice

    Quote Originally Posted by Norm View Post
    0 and null look like the default values for the variables. Make sure the constructor is setting the values of the variables that are being used by the toString() method.
    The set methods aren't posted so I can't see what they are doing. The name variable is getting the value: "John" ok.
    Thanks Norm i just mistaken by the value .didnt see it
    This tread can be close thank you very much

Similar Threads

  1. Need some serious advice
    By Rituparna in forum The Cafe
    Replies: 4
    Last Post: September 25th, 2013, 08:26 AM
  2. [SOLVED] i need an advice!
    By waseem1345 in forum Java Theory & Questions
    Replies: 2
    Last Post: November 14th, 2012, 11:15 AM
  3. Need advice
    By kave2 in forum Loops & Control Statements
    Replies: 6
    Last Post: October 12th, 2012, 07:44 PM
  4. Hello, need some advice.
    By mango7777 in forum Member Introductions
    Replies: 1
    Last Post: June 15th, 2012, 08:10 AM
  5. i need some advice ....
    By mdstrauss in forum Java Theory & Questions
    Replies: 8
    Last Post: July 24th, 2009, 02:29 PM