wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Class and SubClass files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Class and SubClass files" Watch "Class and SubClass files" New topic
Author

Class and SubClass files

Chris Hembel
Greenhorn

Joined: Oct 31, 2012
Posts: 8
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

Joined: Aug 05, 2005
Posts: 3429
    
  12

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
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3429
    
  12
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

Joined: Oct 31, 2012
Posts: 8
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

Joined: Oct 13, 2005
Posts: 38039
    
  22
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class and SubClass files
 
Similar Threads
How do I use a (boolean?) token to reject user input?
Trying to figure out what those mean
To Phrase it another way
GridLayout Manager
New Objects keeping old values