• Post Reply Bookmark Topic Watch Topic
  • New Topic

From Where That "Null" Comes From?  RSS feed

 
Manda Putra
Greenhorn
Posts: 10
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh I Confuse

Badly, i have write a code, when i run it. its work but something make it look bad.
there is a "null" on it. on the output. can anybody help me to remove this "null" ?

here is my code :

And The Output :

Customer Name :
null Woompy Jhonsonnull
Address :
null New Yardnull
Customer Condition :
null Worsenull


I want to remove that "null", from where that "null" comes from?, what should i change to remove that "null"?
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, that is a really confusing program!  I would start over if I were you, but since I'm not, here's what's going on:

What does NM.tipe(String) do?  (I've reformatted the code)

ok is getting 1 (because we don't get an exception) so addressCustomer is getting fill, which is "Woompy Jhonson".  So now:

What is NM.get_fullname()?

get_name() returns nameCustomer, get_address() returns addressCustomer, and get_condtn() returns condCustomer.  But out of those three, only addressCustomer has been set (with the name).  So when you call:

... name and condition are null.  Clear as mud?
 
Manda Putra
Greenhorn
Posts: 10
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My point is writing a program with 3 attributes in private, with inheritance, and constructor. but wow! I ended by writing this... cause i dint know what should i do, and my Teacher gave me those code in class.  Also this is the school homework.

So my mistake is in


I must call customerCondition ? on that.

So Thanks i know where the "null" comes from but, i still dont know how to fix it. 


Knute Snortum wrote:Wow, that is a really confusing program!  I would start over if I were you, but since I'm not, here's what's going on:

What does NM.tipe(String) do?  (I've reformatted the code)

ok is getting 1 (because we don't get an exception) so addressCustomer is getting fill, which is "Woompy Jhonson".  So now:

What is NM.get_fullname()?

get_name() returns nameCustomer, get_address() returns addressCustomer, and get_condtn() returns condCustomer.  But out of those three, only addressCustomer has been set (with the name).  So when you call:

... name and condition are null.  Clear as mud?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manda Putra wrote:
So Thanks i know where the "null" comes from but, i still dont know how to fix it. 


You have a pretty weird design. You have a MyCustomer class, which has fields for the customer name, address, and condition. This part is good.

... but ... you are not really using any of these fields. Instead, you created three new sub classes. A name class, an address class, and a condition class -- and while they inherit from the customer class, they don't actually use these fields of the class. Instead, there is another customer field of the base class that is inherited and used. And finally, you have a method that moves the value from this second customer field to the address field.

To be honest, it looks like your class design is wrong, and needs to be fixed. Perhaps, you should get rid of the three sub classes, and use the base class (with the three fields) only?

Henry
 
Manda Putra
Greenhorn
Posts: 10
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all, I've change the whole program and use a base class with 3 class. and its work more efficient.
so i must learn how to write a program from beginning. I really likes this forum.
Henry Wong wrote:

You have a pretty weird design. You have a MyCustomer class, which has fields for the customer name, address, and condition. This part is good.

... but ... you are not really using any of these fields. Instead, you created three new sub classes. A name class, an address class, and a condition class -- and while they inherit from the customer class, they don't actually use these fields of the class. Instead, there is another customer field of the base class that is inherited and used. And finally, you have a method that moves the value from this second customer field to the address field.

To be honest, it looks like your class design is wrong, and needs to be fixed. Perhaps, you should get rid of the three sub classes, and use the base class (with the three fields) only?

Henry
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's always easier the second time.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!