這是一類學生一組操縱學生
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