This is for an assignment, I'm not asking for answer answers/code to help me out but a point in the right direction would help me greatly.

I have approximately 250 lines of data (olypics data) that I want to load into a constructor and then make an array of said object.

The data about olympic games is just a basic 5 column setup of:

Year, Nation, Gold, Silver, Bronze
1992,Cuba,14,6,11                   <<--output from excel into csv format

and I want to load said data into my constructor

 public POlympics(int year, String nation, int gold, int silver, int bronze) 
        this.year = year;
        this.nation = nation; = gold;
        this.silver = silver;
        this.bronze = bronze;

My problem is, the data if output in csv format...must be loaded as strings into the array (whereas I want the year,gold,silver,bronze as integers for basic calculations in other methods).

What are some simpler ways to load my data into the constructor + array? (without having to make them all strings, then convert them all to ints or floats, and lose marks for it). Alternatives to CSV format which mean I won't have to mess about with Integer.parseInt etc

Cheers :)

 * Created on 16/05/2008, 14:48:07
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.

package polympics;

 * @author Teckiwi
public class OlympicReader {

    public OlympicReader() {
   //POlympics(int year, String nation, int gold, int silver, int bronze)
    public void load(POlympics[] data)
        int i = 0;
        int year;
        String nation;
        int gold;
        int silver;
        int bronze;
        String line;
        try {
            BufferedReader in = new BufferedReader(new FileReader("Data2read.csv"));
            while ((line = in.readLine())!=null) {
                String[] fields = line.split(",");
                data[i]=new POlympics(year, nation, gold, silver, bronze);
            }   catch (IOException e) {
                System.out.println("There was a problem with the file");
            }   //catch


added the parseInt's to my loader class, but a non csv way would be more handy

This article has been dead for over six months. Start a new discussion instead.