• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passing Value from Scanner Class to Class Constructor

 
Greenhorn
Posts: 6
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 https://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.








 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

First, it will help if you added some code tags... like so...

Nigel Foley wrote:




 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 https://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
Posts: 6
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic