**版主能否删除或锁定这个问题,我现在知道答案了,我没有问清楚问题
好的,对不起,我的代码中的所有内容都发布了
import java.util.*;
import java.lang.*;
import java.io.*;
public class MinorAssignment_PartB {
public static void main(String[] args) throws Exception {
List<StudentMarks> marks = new ArrayList<StudentMarks>();
String File = "studentinfo.txt";
Scanner scan = new Scanner(new File(File));
scan.useDelimiter(",");//makes the delimiter a comma
while(scan.hasNext()) {
marks.add(new StudentMarks(scan.next(), scan.next(),
scan.nextDouble(), scan.nextDouble(),
scan.nextDouble(), scan.nextDouble()));
System.out.printf("%-23s %-15s %-15s %-15s " +
"%-15s %-15s %-15s %-15s %n", "STUDENT NAME",
"STUDENT FAN", "PART A", "PART B", "PARTt C",
"PART D", "MARK", "GRADE");
for (int i = 0; i < marks.size(); i++) {
System.out.println(marks.get(i));
}
}
和班级
import java.text.*;
public class StudentMarks {
//contains a student class and an array of doubles.
private Student student = new Student();
private double marks[] = new double[5];
DecimalFormat fmt = new DecimalFormat("0.##");
public StudentMarks(String name, String fan,
double partA, double partB, double partC, double partD) {
Student stud = new Student(name, fan);
this.student = stud;
this.marks[0] = partA;
this.marks[1] = partB;
this.marks[2] = partC;
this.marks[3] = partD;
this.marks[4] = ((partA*0.1) + (partB*0.4) + (partC*0.2) + (partD*0.3));
}
@Override
public String toString() {
return "" + student + "\t" + marks[0] + "\t\t" + marks[1] + "\t\t" + marks[2] + "\t\t" + marks[3] + "\t\t" + fmt.format(marks[4])+"%";
}
}
所以我需要在arraylist的一行中获取一个特定的元素
我有 10 行文本,每行包含 2 个字符串和 2 个像这样的双精度 Adam Adamson adam0001 85.4 79.8 82.4 86.1 9 多行相同格式不同的名称和数字
我有打印第一行的marks.get(0),但我只需要第三个元素,85.4
感谢大家的尝试,但我想通了,抱歉没有很清楚地问问题