这是一类学生一组操纵学生
public class Etudiant {
private int id;
private String name;
private String birthdate;
public Etudiant(int id,String name,String birthdate){
this.id=id;
this.nom=name;
this.birthdate=birthdate;
}
public String getInfo(){
return " "+ this.id+" "+this.name+" "+this.birthdate;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getbirthdate() {
return birthdate;
}
public void setbirthdate(String birthdate) {
this.birthdate=birthdate;
}
我写了一个类Groupe
操纵学生...... 但工作区的错误出现了,当我写我的main
方法
这是我的代码:
import java.util.ArrayList;
import java.util.Scanner;
public class Groupe {
ArrayList <Student> etud = new ArrayList<Student>();
private int id;
private String formation;
public Groupe(int id, String formation) {
this.id = id;
this.formation = formation;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFormation() {
return formation;
}
public void setFormation(String formation) {
this.formation = formation;
}
public void ajouterEtudiant (Student e){ // add a student
Groupe g =new Groupe(this.id, this.formation);
g.etud.add(new Student(e.getId(), e.getName(), e.getbirthdate()));
}
public void supprimerEtudiant(Student e){
Groupe g =new Groupe(id, formation);
if(!g.etud.isEmpty()){
g.etud.remove(e);
}else{
System.out.println("list empty ");
}
}
public void supprimerEtudiant(int id){ // delete a student using the id
int i=0; boolean B =true;
Groupe g = new Groupe(id, formation);
while ((i<g.etud.size())&&(B==true) &&(!g.etud.isEmpty())){
if ((g.etud.get(i)).getId()==id){
g.etud.remove(i);
B=false;
}
i++;
}
}
public void rechercheEtudiantNom(String name){ // search for a student by `enter code here`//his name
int i=0;
Groupe g =new Groupe(this.id, this.formation);
boolean B=true;
while ((i<g.etud.size())&& (B==true)&&(!g.etud.isEmpty())){
if(g.etud.get(i).getname()==name){
B=false;
}
i++;
}
if (B) {
System.out.println("student doesnt exist !");
}else{
System.out.println("student existe !");
}
}
public void afficheTousEtudiant(){ // to show the list of students
Groupe g = new Groupe(this.id, this.formation);
for(int i = 0;i<g.etud.size()-1;i++){
System.out.println(g.etud.get(i).getName());
}
}
}
请告诉我我的方法中的错误在哪里。
什么错误? – rafid059
我没有找到错误..为什么我问....当你写这两个类..然后在MAIN例如创建一个群,然后你添加一个学生,然后你尝试按方法显示列表afficheTousEtudient()。 ...什么也没有显示 –
发布您的主要类与主要方法 – rafid059