Results 1 to 9 of 9
  1. #1
    mikeg is offline Member
    Join Date
    Nov 2010
    Posts
    25
    Rep Power
    0

    Default 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

  2. #2
    venerik is offline Member
    Join Date
    Oct 2010
    Posts
    94
    Rep Power
    0

    Default

    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?
    Erik
    I'm new to Java but I like to help where ever I can. :)

  3. #3
    mikeg is offline Member
    Join Date
    Nov 2010
    Posts
    25
    Rep Power
    0

    Default

    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

  4. #4
    venerik is offline Member
    Join Date
    Oct 2010
    Posts
    94
    Rep Power
    0

    Default

    I think I would create a method that takes the filename as an argument and returns an array of scores. Something like:

    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
    }
    And then in a main loop add the results to the file containing totals.

    Good luck.
    I'm new to Java but I like to help where ever I can. :)

  5. #5
    mikeg is offline Member
    Join Date
    Nov 2010
    Posts
    25
    Rep Power
    0

    Default

    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

  6. #6
    mikeg is offline Member
    Join Date
    Nov 2010
    Posts
    25
    Rep Power
    0

    Default

    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

  7. #7
    venerik is offline Member
    Join Date
    Oct 2010
    Posts
    94
    Rep Power
    0

    Default

    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,
    Erik
    I'm new to Java but I like to help where ever I can. :)

  8. #8
    mikeg is offline Member
    Join Date
    Nov 2010
    Posts
    25
    Rep Power
    0

    Default

    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

  9. #9
    mikeg is offline Member
    Join Date
    Nov 2010
    Posts
    25
    Rep Power
    0

    Default

    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

  1. Problem running Java with XP Pro SP2
    By swarv in forum New To Java
    Replies: 16
    Last Post: 06-23-2010, 01:58 PM
  2. Java Loops - accumulating totals
    By iv3java in forum New To Java
    Replies: 6
    Last Post: 12-15-2009, 05:39 AM
  3. Replies: 0
    Last Post: 08-26-2009, 01:03 PM
  4. running java
    By Winarto in forum New To Java
    Replies: 1
    Last Post: 08-22-2008, 06:40 AM
  5. Running java classes with XML
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 06-29-2007, 03:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •