实际上,我已经在一个班级中创建了一个ArrayList,我需要传递来自另一个班级的学生数据。我能够做到,但是我也想在ArrayList中找到最大的标记值,因为我不能调用getmarks方法。当我尝试调用v.get(i).getmarks()时,.getmarks()下有一条红色的蠕动线。
我的B类(Arraylist类)
public class JavaApplication47 {
private static void println(String message) {
System.out.println(message);
}
private static final int SIZE = 2;
public static void main(String args[]) {
ArrayList v = new ArrayList<>();
Scanner input = new Scanner(System.in);
for (int i = 0; i < SIZE; i++) {
System.out.println("Enter name, age and marks");
v.add(new Student(input.next(), input.nextInt(), input.nextInt()));
}
Student top = null;
int maxmarks = 0;
for (int i = 0; i < v.size(); i++) {
if (v.get(i).getmarks > maxmarks) {
top = (Student) v.get(i);
}
maxmarks = v.get(i).getmarks();
}
if (top != null) {
println("Top Student Details : ");
println("Name : " + top.getName());
println("Age : " + top.getAge());
println("Marks : " + top.getmarks());
}
}
}
我的A类(学生班)
public class Student {
private String name;
private static int marks, age;
public Student(String name, int age, int marks) {
this.name = name;
this.age = age;
this.marks = marks;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public static int getmarks() {
return marks;
}
}