Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

i need help on java method please

 
brando brandido
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

i am a bit confuse with the output of my code

this is my text file


and this is my java code



The objective of this code is to get the employee id of employees and then display employee details.

e.g. you type an employee id 2006-0031

the code will then read the text file and when that employee id is found, it then display the name of employees and other details such as employee name, base pay, net pay.

The problem with my code is that when i type the employee id 2001-0001 it displays the output correctly
but when i type an employee id 2006-0031 or 2010-0008 i will get an error.

What is wrong with my code? what is the correct coding?
 
Niraj Jha
Ranch Hand
Posts: 63
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is because of calling readLine() method three times(Line number 14 , 27, 29 on br).Call it once and match your condition.......
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are all your methods static?
 
brando brandido
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Niraj Jha wrote:It is because of calling readLine() method three times(Line number 14 , 27, 29 on br).Call it once and match your condition.......


ok i have changed it to



and now i can get the first employee id when i input 2006-0031

but then the 2nd and 3rd it displays 'no employee records!'
 
brando brandido
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Why are all your methods static?


The instructions is use three methods and so therefore that what i did. Please correct me, i am beginner to java. I am willing to learn.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it is always bad when people hand out assessments telling students how many methods to use.
But that does not explain why you have made all your methods static.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic