All things are lawful, but not all things are profitable.
There are three kinds of actuaries: those who can count, and those who can't.
Knute Snortum wrote:Do you know Regular Expressions (regex)? They can be complex but they are designed for this kind of stuff. Look at java.util.regex.Pattern.
Piet Souris wrote:Isn't it very much easier to open this file in excel or libreoffice,
and derive the average rainfall with a couple of mouseclicks?
There are three kinds of actuaries: those who can count, and those who can't.
Stefan Evans wrote:(...)
Is this screenshot an exact example of what the file looks like or a conceptual one? I don't see any rainfall data in it is all :-)
There are three kinds of actuaries: those who can count, and those who can't.
I'm gonna make a 2D array table for each city with the number of rows and 7 columns as I have 7 columns in every data list and variable rows that goes up to 1257 rows
Carey Brown wrote:
Stefan Evans wrote:So the point Carey was making with that code sample is
Step 1: Read the data from the file into a data structure of some sort. In this case, he is suggesting a List of "MonthlyRecord" objects, where each monthly record object stores the data from one line in the input file...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Stefan Evans wrote:So the point Carey was making with that code sample is
Step 1: Read the data from the file into a data structure of some sort. In this case, he is suggesting a List of "MonthlyRecord" objects, where each monthly record object stores the data from one line in the input file...
And I'd go even further than that. A MonthlyRecord class should hold ALL the information you need to store, viz:and furthermore, IT should be responsible for pulling it's values from a "record" (presumably a line of text), viz:and then you can add it to your list with something like:
MonthlyRecord mr = new MonthlyRecord( myFile.readLine() );
records.add(mr);
and then sort/extract/muck about with it all you want.
HIH
Winston
All things are lawful, but not all things are profitable.
saeid jamali wrote:What about this? does do the job?
If yes then why do I need String[] fields = record.split("\\s+");in my public class as shown above? cause without the split I was getting Format exception.
and another thing is with this structure I have to be able to print the value of the tmax like System.out.println(MonthlyRecord.tmax()); is it right? so I can print it, calculate it or do what ever with it.
Guys sorry for asking too many questions but every time you guys mention something I read about it and I'm really interested to learn java. I learnt a lot of stuff from this forum more than any classes.
All things are lawful, but not all things are profitable.
Knute Snortum wrote:I looks like what you wanted to use was replaceAll(). It takes a regex.
All things are lawful, but not all things are profitable.
saeid jamali wrote:Then in my constructor class I have the following just before parse the records...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:... I'd suggest writing a
public static final boolean isHeader(String record) { ...
method...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Winston Gutkowski wrote:... I'd suggest writing a
public static final boolean isHeader(String record) { ...
method...
Or possibly even better, a:
public static final boolean isValidData(String record) { ...
method that checks that everything in the record is correctly formatted, eg:I leave the tests up to you.
Winston
All things are lawful, but not all things are profitable.
Knute Snortum wrote:It's hard to tell what the problem is without the code you've written. Can you post your entire code here?
saeid jamali wrote:and this is my constructor:
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
saeid jamali wrote:and this is my constructor:
Well that's wrong right there isn't it? In fact, practically all your conversions are.
Look at your data. HARD.
Winston
saeid jamali wrote:Do you think so? are you saying this because of "---" sign? if yea this sign can be any where in the data as you can see tmax, tmin, sunny columns also have this ("---") and I have 4 more files formatted exactly the same but this "---" can be found any where...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
No. But you can read them and do not do nothing with them. For reading you're using readLine method, so think of how to read 7 lines and do not do nothing with them, and only from line 8 start your processing.saeid jamali wrote:is there any way to ignore first 7 lines?
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |