my dog learned polymorphism
The moose likes Beginning Java and the fly likes Passing Value from Scanner Class to Class Constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Passing Value from Scanner Class to Class Constructor" Watch "Passing Value from Scanner Class to Class Constructor" New topic
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
    
  19


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
    
  19

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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Passing Value from Scanner Class to Class Constructor
 
Similar Threads
help with this program! I am stuck
Finishing Driver Help, Null error
validation problem.
help looping through objects
Simple java bean problem