我想比较数组中字符串形式的学生人数与人数n
这是字符串。
remarque:
班级形成:
私有字符串代码;
私有字符串名称;
private int nbsi = 0;
私人学生[]标签=新学生[200];
班级学生:
私有字符串号;
``
私有字符串名称;
私有字符串name2;
public Module []选项卡= new Module [4];
块引用类的形成
package tp2_bis;
public class Formation
{
//question 2
private String code;
private String name;
private int nbsi=0;
private Student [] tab = new Student[200];
//question 3
public Formation(String code,String name)
{
this.setCode(code);
this.setName(name);
}
public Formation()
{
}
//question 4
public String getCode()
{
return code;
}
public void setCode(String code)
{
this.code = code;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getNbsi()
{
return nbsi;
}
public void setNbsi(int nbsi)
{
this.nbsi = nbsi;
}
//question 6_b
public boolean searchName(String n1)
{
int i=0;
boolean b=false;
while(!b && i
{
if(tab[i].getName().equals(n1)) //there is the problem i cant compare between them??
b=true;
else
i++;
}
return b;
}
}
班级班级学生=>班级组建
package tp2_bis;
public class Student
{
//question 2
private String number;
private String name;
private String name2;
public Module[] tab = new Module[4];
//question 3
public Student(String name,String name2)
{
this.setName(name);
this.setName2(name2);
}
public Student()
{
}
//question 4
public String getNumber()
{
return number;
}
public void setNumber(String number)
{
this.number = number;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getName2()
{
return name2;
}
public void setName2(String Name2)
{
this.name2 = name2;
}
public Module[] getTab()
{
return tab;
}
public void setTab(Module[] tab)
{
this.tab = tab;
}
//question 5_a
public void addMark(Module m)
{
int i=0;
boolean b=false;
while(i<4 && !b)
{
if(this.tab[i]==null)
{
this.tab[i]=m;
b=true;
}
else
i++;
}
}
public void addMark(String name,double mark,int cof)
{
Module m=new Module(name,mark,cof);
int i=0;
boolean b=false;
while(i<4 && !b)
{
if(this.tab[i]==null)
{
this.tab[i]=m;
b=true;
}
else
i++;
}
}
public void write()
{
Module[] tab1= this.tab;
System.out.println("numero d'inscription:"+this.getNumber()+
"\nNom et Prenom de l'etudiant: "+this.getName()+" "+this.getName2()+
"\nNotes:");
}
Blockquote的主要功能
package tp2_bis;
public class TestFormation
{
public static void main(String[] args)
{
Formation f=new Formation("CPI_2016","class of computer science");
Etudiant e1=new Etudiant("ali","djamel");
Etudiant e2=new Etudiant("karim","rachid");
f.inscription(e1);
f.inscription(e2);
Module m1=new Module("algo",19,5);
e1.addMark(m1);
e1.addMark("analyse",17,5);
m1=new Module("algebre",20,3);
e1.addMark(m1);
m1=new Module("archi",15,4);
e1.addMark(m1);
e1.write();
e2.addMark(new Module("algo",17,5));
e2.addMark(new Module("analyse",18,5));
e2.addMark("algebre",20,3);
e2.addMark("archi",15,4);
e2.write();
System.out.println(f.searchName("karim"));
}
}