【发布时间】:2021-04-12 00:51:07
【问题描述】:
我刚刚开始学习 java renow。我创建了一个包含变量 ID 和名称的班级学生和另一个班级学生列表,它是一个学生的数组列表。
我想创建允许传递变量的特技类名称(ID 或名称)和变量值的 seach 函数。我该怎么做?
class Student{
String ID;
String name;
public Student(){
}
public Student(String ID,String name){
this.ID = ID;
this.name = name;
}
public String getStudent() {
String info = this.ID +"\t\t\t"+ this.name;
return info;
}
}
class StudentList{
private ArrayList <Student> list = new ArrayList<>();
private int counter = 0;
static Scanner sc = new Scanner(System.in);
public StudentList(){
}
public StudentList(Student stu){
Student student = new Student(stu.ID,stu.name);
this.list.add(student);
this.counter++;
}
public int seach(String type(name or ID) , String value ){
int i;
int found = 0;
for(i = 0; i < list.size();i++){
if(value.equals(list.get(i).type){
found++;
System.out.println(value.equals(list.get(i).type);
}
}
return found;
}
}
【问题讨论】:
标签: java class variables methods