r/javahelp • • Nov 06 '19

Going crazy, need help with a program

Hi guys, I'm an ansipring java developer. My developer friend gave me an exercise and I can't for the life of me figure out how to do it. If you guys could help I would be so grateful.

This is the exercise:

Given a weather.dat file, write a program that given the file in input returns the day with the biggest and lowest temperature range. In this file there are 30 days and there's a lot of data for these days, but the temperature columns are the second and third one. So it's like : Day | Max Temp | Lowest Temp| ecc | ecc | ...

I understood I have to use Java Arrays and I managed to have the program read all the file but I don't know how to proceed. Help, thanks lol

16 Upvotes

13 comments sorted by

View all comments

1

u/techtamashi Nov 06 '19
  1. Read the file line by line

  2. Save each line to a String

  3. Java has a String Split method that can split a String to an array of Strings based on the character(s) you want to split on - in this case, you would split based on the | character

  4. Next you would convert the values in the 2nd and 3rd places to Integers or Floating point numbers as appropriate and calculate the difference between them. Save the differences to a Map of Day and Range (i.e. difference).

  5. Finally iterate over the Map and identify which Day has the min and max difference - which represent the days with the lowest and highest temperature ranges.