aspose file tools*
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
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: 3539
    
  15

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: 3539
    
  15
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: 38818
    
  23
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