• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Is there a way to display a specify line from the files.csv ?

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm looking at how to process each line of data, print the results for that person, then read the next line. Without reading the entire file into an array before processing the data I need suggestions.
 
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you're not reading the entire file into an array, just one line at a time.

Are any of the fields in the data quoted?  Like..

10, "Snortum, Knute", 13.32

In the line above, there are only three fields and the second field is "Snortum, Knute".  If you have data like that, I'd suggests using Apache's Commons-CSV.
 
Abdallah Taha
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:Well, you're not reading the entire file into an array, just one line at a time.

Are any of the fields in the data quoted?  Like..

10, "Snortum, Knute", 13.32

In the line above, there are only three fields and the second field is "Snortum, Knute".  If you have data like that, I'd suggests using Apache's Commons-CSV.


Yes, it like that.  

Fred Jones 42,492.34 1 A 2,218.23
Sally  O'Brien     48,721.66 2 i       18,230.12

 
Marshal
Posts: 27371
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. So your original question was, you didn't want to read the original file into an array. And the code you posted doesn't do that, so that question was answered.

In fact your posted code takes care of all of your requirements, pretty much. The only thing in which needs fixing is that you're closing the Scanner after reading the first line, which you don't want to do that. Close it outside the loop, or -- since you're using try-with-resources, you don't need to close it yourself at all.
 
Abdallah Taha
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you,
I want to add Fred number to Sally?
 
Paul Clapham
Marshal
Posts: 27371
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then you have to get Fred's number out of the file, and get Sally's number out of the file, and add those two numbers together.

So... there's three things you need to do once you break down your requirement into smaller steps. (Which you should always try to do that.)

The first thing is, get Fred's number out of the file. How would you do that?
 
Marshal
Posts: 76447
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wouldn't you want to get Fred's line first, then identify it, then look for the number?
 
Marshal
Posts: 8417
606
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sine Java 8 there is a less error prone way of reading file line by line.

Look at these Google search results.
 
Abdallah Taha
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'mlooking to do Fred values  42,492.34 minus Sally values 18,230.12.
42,492.34 - 18,230.12
Do I need to do an array two-dimension to do this calculation.
 
Campbell Ritchie
Marshal
Posts: 76447
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Abdallah Taha wrote:. . . Do I need to do an array two-dimension to do this calculation.

No, for two reasons:-
  • 1: You can probably solve the probeproblem some other way.
  • 2: An array woiuld be an implementaion detail; Since you haven't yet decided on the logic of the probeproblem, you shouldn't be thinking about implementations yet.


  • edit: Correct probe to problem and ine to since.
     
    Dinner will be steamed monkey heads with a side of tiny ads.
    the value of filler advertising in 2021
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic