Results 1 to 9 of 9
Thread: Running totals in java. HELP!
- 11-15-2010, 09:15 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 25
- Rep Power
- 0
Running totals in java. HELP!
I don't know if this is possible in java as I am relatively new to java programming but was hoping someone would be able to offer some advice? I have written a piece of code that reads in a csv file consisting of three columns of doubles and calculated the average of each column. If the average values are between certain ranges of values then a score of 0, 1, 2, or 3 will be allocated. I want to then store these scores somehow so that I can read in a second file and allocate further scores depending on the new average values. These scores then need to be stored in the same place as the first scores. I will then keep adding new scores from further files and need to determine a running total of the scores. I hope that makes sense and if so how do I go about coding this??
Many thanks in advance
- 11-15-2010, 09:39 PM #2
Member
- Join Date
- Oct 2010
- Posts
- 94
- Rep Power
- 0
To make sure I understand your problem. You want to read several files with three columns of doubles.
For every file you want to determine the average per column and assign scores to these averages.
Finally all scores need to be stored in a file.
Are we on the same page?
ErikI'm new to Java but I like to help where ever I can. :)
- 11-15-2010, 09:55 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 25
- Rep Power
- 0
Hi Erik. Yes that's correct. I need to store a score for each column average and write to a file. Then read in a second file and store a score for each column average in the new file. I will then keep adding files and scores until a certain running total is reached. Once this running total, say 10, for any column then the running total is set back to zero and it starts again. Thanks for your quick reply.....again!!
Many thanks
Mike
- 11-15-2010, 10:36 PM #4
Member
- Join Date
- Oct 2010
- Posts
- 94
- Rep Power
- 0
I think I would create a method that takes the filename as an argument and returns an array of scores. Something like:
And then in a main loop add the results to the file containing totals.Java Code:public int[] getScores(String filename) { // the (slightly modified) code of [URL="http://www.java-forums.org/new-java/34665-reading-csv-file-into-2d-array-help.html"]your other thread[/URL] here }
Good luck.I'm new to Java but I like to help where ever I can. :)
- 11-15-2010, 10:50 PM #5
Member
- Join Date
- Nov 2010
- Posts
- 25
- Rep Power
- 0
Ok thanks for that Erik. I'll see if I can have a go at what you suggest and let you know how I get on. Thanks again
Mike
- 11-16-2010, 08:12 PM #6
Member
- Join Date
- Nov 2010
- Posts
- 25
- Rep Power
- 0
Hi Erik. I've managed to write code to calculate the average scores and write them to a text file. I have then written code to read the values from the text file created in order to calculate the total score. I have managed to get the code to work in as far as it appends new score values to the end of the text file everytime I calculate new averages. The problem I'm having is when I write the scores to the text file, which are either the values 0,1,2 or 3, the text file doesn't actually show numbers but some sort of square code; maybe some sort of ASCII code? Consequently when I try and read those values back in to calculate the running total I just get an input error. I am using a BufferedWriter to write the scores to the text file and then a BufferedReader to read the scores back in. Any ideas??
Many thanks in advance
Mike
- 11-16-2010, 09:08 PM #7
Member
- Join Date
- Oct 2010
- Posts
- 94
- Rep Power
- 0
Hi Mike,
Your scores are written as bytes I think. So instead of the ASCII code of 0 (i.e. 48) the byte 0 itself is being written.
Sadly I have no experience in writing formatted text to files. I suppose one of the other forum members should come to help.
Maybe you could have a look at the Formatter class. I think that class could be of help.
Good luck,
ErikI'm new to Java but I like to help where ever I can. :)
- 11-16-2010, 09:14 PM #8
Member
- Join Date
- Nov 2010
- Posts
- 25
- Rep Power
- 0
Ok no problem at all. That gives me enough info anyway to get started and think I'll probably figure it out from there. Thank you very much for your help again
Mike
- 11-19-2010, 09:29 AM #9
Member
- Join Date
- Nov 2010
- Posts
- 25
- Rep Power
- 0
Hi Erik,
Just thought I would let you know that I managed to crack the problem with the java program writing bytes to the text file. Instead of using the command file.out(score) to write the scores to the text file I just used file.out(String.valueOf(score)) to write the actual value. Seems to work fine now.
Thanks
Mike
Similar Threads
-
Problem running Java with XP Pro SP2
By swarv in forum New To JavaReplies: 16Last Post: 06-23-2010, 01:58 PM -
Java Loops - accumulating totals
By iv3java in forum New To JavaReplies: 6Last Post: 12-15-2009, 05:39 AM -
Problem in running Java swing wizard in jre 1.6 while it is running in jre 1.4
By Sanjay Dwivedi in forum AWT / SwingReplies: 0Last Post: 08-26-2009, 01:03 PM -
running java
By Winarto in forum New To JavaReplies: 1Last Post: 08-22-2008, 06:40 AM -
Running java classes with XML
By ai_2007 in forum Advanced JavaReplies: 1Last Post: 06-29-2007, 03:20 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks