Java Array Sort String和Int with Methods

时间:2014-03-25 20:33:04

标签: java arrays string sorting int

这是我的数据;

我正在尝试将数据排序到对象中,并且我遇到了很多错误,有人可以运行代码吗?将数据放入Readme.txt文件并尝试查看它是否有效。

ZimmermanD,2,88,75,76,
RegoneN,1,100,96,100,
BrennonT,2,74,80,85,
MouseM,1,87,83,90,
ByrdT,2,78,77,80,
WashingtonD,1,95,76,76,
EricX,2,83,93,95,
HouseS,1,91,71,91,
ShawI,2,74,71,91,
BarberP,1,88,85,92,
CharlesD,2,86,95,81,
DunlapK,2,91,95,70,
JoeS,1,84,93,71,
MatthewD,2,81,89,75,
BrianW,1,98,74,71,
RichardC,2,96,100,98,
SahanaG,1,87,89,88,
MichaleF,2,94,88,96,
AarushiA,1,74,77,74,
SahanaG,2,70,73,79,

类CIAADemo

 import java.io.*;
 import java.util.StringTokenizer;
 public class CIAADemo
 {
    public static void main(String[] args) throws IOException{
        int num_schools = 18; //counts
        String[] CIAAData = new String[num_schools]; //out of index
        String[] student = new String[num_schools];
        int[] category = new int[num_schools];
        int[] round1 = new int[num_schools];
        int[] round2 = new int[num_schools];
        int[] round3 = new int[num_schools];
        FileReader freader = new FileReader("Readme.txt");
        BufferedReader inputFile = new BufferedReader(freader);
        // Create an object
        CIAA report = new CIAA(num_schools);
        // Read the data from the fileen

        for (int index = 0; index < num_schools; index ++)
        {
            CIAAData[index] = inputFile.readLine();
        }
        inputFile.close();
        for (int index = 0; index < CIAAData.length; index++)
        {
            StringTokenizer strTokenizer = new StringTokenizer(CIAAData[index],",");
            {
                student[index] = strTokenizer.nextToken();
                category[index] = Integer.parseInt(strTokenizer.nextToken());
                round1[index] = Integer.parseInt(strTokenizer.nextToken());
                round2[index] = Integer.parseInt(strTokenizer.nextToken());
                round3[index] = Integer.parseInt(strTokenizer.nextToken());
                report.setStudent(student[index],index);
                report.setCategory(category[index], index);
                report.setRound1(round1[index], index);
                report.setRound2(round2[index], index);
                report.setRound3(round3[index], index);
            }
        }
        System.out.println("Schools");
        for(int index = 0; index < student.length; index++)
        {
                System.out.println(student[index] + " " + category[index] + " "
                + round1[index] +" " + round2[index] + " " );
                    System.out.println();}}

        }

班级CIAA

      /**
      * Write a description of class CIAA here.
      * 
      * @author (your name) 
      * @version (a version number or a date)
      */
      public class CIAA
      {
      // instance variables - replace the example below with your own
      private int num_schools;
      private String[] student;
      private int[] category;
      private int[] round1;
      private int[] round2;
      private int[] round3;
      /**
      * Constructor for objects of class CIAA
      */
      public CIAA(int num_schools)
      {
      // initialise instance variables
     student = new String[num_schools];
     category = new int[num_schools];
     round1 = new int[num_schools];
     round2 = new int[num_schools];
     round3 = new int[num_schools];
     }
     public void setStudent(String studentname, int index)
     {
    student[index] = studentname;
     }
    public void setCategory(int categorynumber, int index)
    {
    category[index] = categorynumber;
    }
    public void setRound1(int round1number, int index)
    {
    round1[index] = round1number;
    }
    public void setRound2(int round2number, int index)
    {
    round2[index] = round2number;
    }
    public void setRound3(int round3number, int index)
    {
    round3[index] = round3number;
    }
    }

1 个答案:

答案 0 :(得分:0)

它没有错误,这是输出。你得到了什么错误?

Schools
ZimmermanD 2 88 75 

RegoneN 1 100 96 

BrennonT 2 74 80 

MouseM 1 87 83 

ByrdT 2 78 77 

WashingtonD 1 95 76 

EricX 2 83 93 

HouseS 1 91 71 

ShawI 2 74 71 

BarberP 1 88 85 

CharlesD 2 86 95 

DunlapK 2 91 95 

JoeS 1 84 93 

MatthewD 2 81 89 

BrianW 1 98 74 

RichardC 2 96 100 

SahanaG 1 87 89 

MichaleF 2 94 88