This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
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.
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.
Joined: Aug 05, 2005
And in your other methods there is no need to declare and initialise your String variable before using it
could be better written as this
Joined: Oct 31, 2012
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.
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.