Java 修改和显示学生详细信息
我正在制作一个Java程序来管理学生的详细信息,并希望在修改和显示学生详细信息方面得到一些帮助 这是我为搜索一个学生而编写的代码,我曾考虑过回收代码来修改和显示一个学生,但是,我被卡住了Java 修改和显示学生详细信息,java,Java,我正在制作一个Java程序来管理学生的详细信息,并希望在修改和显示学生详细信息方面得到一些帮助 这是我为搜索一个学生而编写的代码,我曾考虑过回收代码来修改和显示一个学生,但是,我被卡住了 public static void searchStudent(){ try{ BufferedReader readFile = new BufferedReader(new FileReader(file)); System.out.println("--- S
public static void searchStudent(){
try{
BufferedReader readFile = new BufferedReader(new FileReader(file));
System.out.println("--- Searching for a Student ---");
System.out.print("Enter Student Number, Last Name or First Name: ");
String option = sc.nextLine();
System.out.println("Searching for '" + option + "' in the Student File");
System.out.print("\n");
while((line = readFile.readLine()) != null){
int indexFile = line.indexOf(option);
if(indexFile > -1){
System.out.println(line);
System.out.print("\n");
}
}
readFile.close();
} catch(IOException ioe){
System.out.println("Error Searching for a Student !!!");
}
}
这是我展示一个学生的代码,关于如何解决这个问题有什么建议吗?提前谢谢
public static void displayStudent(){
try{
BufferedReader readFile = new BufferedReader(new FileReader(file));
System.out.println("--- Displaying Student Details ---");
System.out.print("Enter Student Number: ");
String option = sc.nextLine();
System.out.println("Searching for Student '" + option + "' in the Student File");
System.out.print("\n");
while((line = readFile.readLine()) != null){
int indexFile = line.indexOf(option);
if(indexFile > -1){
System.out.println("Student Number: " + myArray.get(line)[0]);
System.out.println("Last Name: " + myArray.get(line)[1]);
System.out.println("First Name: " + myArray.get(line)[2]);
System.out.println("Email Address: " + myArray.get(line)[3]);
System.out.println("Mobile Number: " + myArray.get(line)[4]);
}
}
readFile.close();
} catch(IOException ioe){
System.out.println("Error Displaying a Student !!!");
}
}
ArrayList myArray由以下内容填充:
for(int x = 0; x < myArray.size(); x++){
bw.write(myArray.get(x)[0] + ";");
bw.write(myArray.get(x)[1] + ";");
bw.write(myArray.get(x)[2] + ";");
bw.write(myArray.get(x)[3] + ";");
bw.write(myArray.get(x)[4] + ";");
bw.write(System.getProperty("line.separator"));
}
for(int x=0;x
而不是:
myArray.get(line)[0]
使用:
所以在这里,你们通过索引访问列表元素,一旦你们得到了元素,你们就会尝试从列表中访问学生的名字等
我建议您使用Student对象,并将数字、名称等作为Student对象的字段,而不是使用数组。是否有任何错误/异常等?您的问题是什么?错误:方法ArrayList.get(int)不适用(实际参数字符串无法通过方法调用转换转换为int)如何填充myArray,即aray列表?请共享所有相关代码。静态ArrayList myArray=new ArrayList();我通过BufferedWriterOh填充了一行哇,Java真的很复杂,一个错误的动作,它可能会毁掉你的整个程序。我从未意识到我需要使用“indexFile”而不是“line”,因为它已经连接了。。谢谢。我从来没有使用过勾号按钮,因为我很少使用stackoverflow,我会这样做来支持你!再次感谢!
myArray.get(indexFile)[0]