• 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

i need help on java method please

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 63
Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.......
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are all your methods static?
 
brando brandido
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic