| Author |
Passing Value from Scanner Class to Class Constructor
|
Nigel Foley
Greenhorn
Joined: Dec 08, 2012
Posts: 6
|
|
Hi All,
I am new to this forum/java programming so I apologise in advance if I explain this incorrectly
I have a main method that takes values from the scanner and passes them to the customer object
}
When I run this code the customer object is instantiated but it is set to default field values and not to the values that are picked up by the scanner.
I have found a similar thread http://www.coderanch.com/t/408970/java/java/passing-arguments-constructor
but don't quite understand what is going on.
I would really appreciate it, if somebody could spare time to have a look and help me out
Thanks
Nigel
I have attached the associated Customer code below in case it is needed.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16687
|
|
First, it will help if you added some code tags... like so...
Nigel Foley wrote:
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16687
|
|
Nigel Foley wrote:Hi All,
I am new to this forum/java programming so I apologise in advance if I explain this incorrectly
I have a main method that takes values from the scanner and passes them to the customer object
...
When I run this code the customer object is instantiated but it is set to default field values and not to the values that are picked up by the scanner.
I have found a similar thread http://www.coderanch.com/t/408970/java/java/passing-arguments-constructor
but don't quite understand what is going on.
I would really appreciate it, if somebody could spare time to have a look and help me out
Thanks
Nigel
Hint: take a look at the constructor of your user class...
What is it that you are attempting to do?? (hint: it is not what you think it is)
And BTW, welcome to the ranch.
Henry
|
 |
Nigel Foley
Greenhorn
Joined: Dec 08, 2012
Posts: 6
|
|
Hi Henry,
Thanks for pointing me in the right direction, I changed up the constructor to use the 'this' keyword(now I reference the current object) and everything work fine.
Nigel
|
 |
 |
|
|
subject: Passing Value from Scanner Class to Class Constructor
|
|
|