1
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Hashtable;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVRecord;
import org.knowm.xchart.XChartPanel;
import org.knowm.xchart.XYChart;

public class App extends JFrame {
    static int fieldcounter = 0;

    private static final long serialVersionUID = 1L;

    public static void main(String[] args) throws IOException {

        JFrame frame = new JFrame();

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.setVisible(true);
        frame.setFocusable(true);

        JPanel panel = new JPanel();

我的哈希表来分隔每一列(3,4,5):

        Hashtable<Double, String> ht = new Hashtable<Double, String>();
        Hashtable<Double, String> ht1 = new Hashtable<Double, String>();
        Hashtable<Double, String> ht2 = new Hashtable<Double, String>();
        Hashtable<Double, String> ht3 = new Hashtable<Double, String>();

        ArrayList<Integer> cohort = new ArrayList<Integer>();
        cohort.add(1980);
        cohort.add(1981);
        cohort.add(1982);
        cohort.add(1983);
        cohort.add(1984);
        cohort.add(1985);
        cohort.add(1986);
        cohort.add(1987);
        cohort.add(1988);
        cohort.add(1989);
        cohort.add(1990);
        cohort.add(1991);

        frame.add(panel);
        JButton cohor = new JButton();

        XYChart c = new XYChart(600, 600);
        XChartPanel<XYChart> chart = new XChartPanel<XYChart>(c);

        panel.add(chart);
        String chhart = "";
        double n = 0.0;

        // _____________________
        File file = new File("/Users/josephmuzzin/Desktop/mrc_table9.csv");
        BufferedReader br = new BufferedReader(new FileReader(file));

逐个字段读取 csv 字段:

        for (CSVRecord record : CSVFormat.DEFAULT.parse(br)) {
            for (String field : record) {
                fieldcounter++;

                for (n = 0; n < 100; n++) {

                    switch (fieldcounter) {

                    case 9:
                        ht.put(n, field);
                        break;

                    case 10:
                        ht1.put(n, field);
                        break;

                    case 11:
                        ht2.put(n, field);
                        break;

                    case 12:
                        ht3.put(n, field);
                        fieldcounter = 6;
                        break;
                    }
                }

            }

        }
        System.out.println(ht);
        System.out.println(ht1);
        System.out.println(ht2);
        System.out.println(ht3);

    }

}[csv file][1]

我需要帮助将百分位数与收入/工资配对(第 1 列(百分位数)、3、4、5)。我正在尝试使计数器上升到 99.99,并将第 3、4、5 列与每个百分位数配对,但我无法让它们以正确的方式阅读。

4

0 回答 0