java taplam

public class Monhoc {

String tenmh;

float diem;

public Monhoc(String m, float d)

{

tenmh = m;

diem = d;

}

public String getTen()

{

return tenmh;

}

public float getDiem()

{

return diem;

}

}

-----------------------------

public class Sinhvien {

public final int SL = 2;

String t;

int ns;

Monhoc mh[];

public Sinhvien(String ten, int nam, Monhoc mon[])

{

t = ten;

ns = nam;

mh = mon;

}

public boolean khoaLuan()

{

return (((this.tong()/2)>=7) && (mh[1].getDiem()>=5) && (mh[2].getDiem()>=5))?true:false;

}

public boolean thiTN()

{

return (!khoaLuan() && (mh[1].getDiem()>=5) && (mh[2].getDiem()>=5) )?true:false;

}

public String tenThiLai()

{

String out=null;

for(int i = 1; i<= SL; i++)

{

if(mh[i].diem < 5)

out = out + " " + mh[i].tenmh;

}

return out;

}

private float tong()

{

return (mh[1].getDiem() + mh[2].getDiem());

}

}

--------------------------------NEW-------------------------------

public class Monhoc {

String tenmh;

float diem;

public Monhoc(String m, float d)

{

tenmh = m;

diem = d;

}

public String getTen()

{

return tenmh;

}

public float getDiem()

{

return diem;

}

}

---------------

public class Sinhvien {

public final int SL = 2;

String t;

int ns;

Monhoc []mh = new Monhoc[2];

public Sinhvien(String ten, int nam, Monhoc m1, Monhoc m2)

{

t = ten;

ns = nam;

mh[0] = m1;

mh[1] = m2;

}

public boolean khoaLuan()

{

return (((this.tong()/2)>=7) && (mh[0].getDiem()>=5) && (mh[1].getDiem()>=5))?true:false;

}

public boolean thiTN()

{

return (!khoaLuan() && (mh[0].getDiem()>=5) && (mh[1].getDiem()>=5) )?true:false;

}

public String tenThiLai()

{

String out = new String();

for(int i = 0; i< SL; i++)

{

if(mh[i].diem < 5)

out = out + " " + mh[i].tenmh;

}

return out;

}

private float tong()

{

return (mh[0].getDiem() + mh[1].getDiem());

}

}

-----------

public class RunSV {

/**

* @param args

*/

public static void main(String[] args) {

Monhoc m1 = new Monhoc("sinh", 4);

Monhoc m2 = new Monhoc("Toan", 3);

Sinhvien sv = new Sinhvien("hung", 1970, m1, m2);

if(sv.khoaLuan())

System.out.println("Lam khoa luan");

else

System.out.println("khong lam khoa luan");

System.out.println(sv.tenThiLai());

}

}

Bạn đang đọc truyện trên: AzTruyen.Top

Tags: #nhatvuong