Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

what is the error in this program  RSS feed

 
Greenhorn
Posts: 16
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the question-Write a class for Employee. Variables contained in the class are id, name and department. Create 10 objects for Employee class and store them in the array. While creating the object, values for the variables are obtained as input from the user. Iterate the array and print the details of the employee.

and my program is


i couldn't able to enter the values for name. this is my output


 
Marshal
Posts: 59700
187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The nextLine() method of Scanner doesn’t do what you think it does. Some books are unclear about it; in fact I use it as a test when reviewing a book: have they got nextLine() wrong?
The API is correct, but not easy to understand, so ignore the rants in this post, and see how nextLine works.
 
Campbell Ritchie
Marshal
Posts: 59700
187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way: why are you using a List when the question clearly says “array”?
 
s john smith
Greenhorn
Posts: 16
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot. i corrected my code. is this correct?
 
Campbell Ritchie
Marshal
Posts: 59700
187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I enter

123456 Campbell Ritchie FMPRG

. . . as one line, what will happen?

Do you think it is correct code? Or what do you think is wrong with it?
 
s john smith
Greenhorn
Posts: 16
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no i cant enter it in a line. i should enter the values line by line. but is there any way to type it in a single line
 
Campbell Ritchie
Marshal
Posts: 59700
187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could have done it with a Scanner. Only you would have to find some way to join the two halves of the name. Or have firstName and lastName fields in the Employee class.
Did you follow the links I provided yesterday? I think they would have sorted out your problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!