gpt4 book ai didi

Java Array 使用方法对 String 和 Int 进行排序

转载 作者:行者123 更新时间:2023-11-29 08:51:06 24 4
gpt4 key购买 nike

这是我的数据;

我正在尝试将数据分类到对象中,但我遇到了很多错误,有人可以运行代码吗?把数据放到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;
}
}

最佳答案

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

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

关于Java Array 使用方法对 String 和 Int 进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22645659/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com