• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class and SubClass files

 
Chris Hembel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created two class files. One is a SubClass of the other. When I run my Subclass with the "public static void main (String[] args)" code in it it goes through the program flawlessly, except that it does not return the custName String correctly. Instead it displays "null" where I have entered my name. I don't understand what I am doing wrong. All the other input items get converted from String to Int or Doubles and the returns are correct. What am I missing.

This is my code For the first Class File:



This is the code for my other file:


Any help will be appreciated.

chembel
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In your inputCustName method you are declaring a local variable with the same name as your instance variable and it is that variable that gets set to the entered name.
Remove line 3 and it should work okay.


And try to remember to UseCodeTags when including code. It makes it a lot easier to read.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And in your other methods there is no need to declare and initialise your String variable before using it
This

could be better written as this

 
Chris Hembel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne,

Thank you so much. As you can see I am a real greenhorn at this.

I really appreciate your suggestions and I will watch my posts more closely when posting code.

Chris
 
Campbell Ritchie
Sheriff
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added code tags, as Joanne suggested, only to find your last option pane call was too long. Don’t use such long lines; you can see from the new version how to split a line. Also don’t use \n; String#format and the %n tag might be the best solution for your String there. Use spaces, not tabs, for indenting.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic