public class SinhVien {
private String maSV, hoTen;
private boolean gioiTinh;
private double diemTB;
public String xepLoai(){
if(diemTB<3.5) return " Kem ";
if(diemTB<5) return " Yeu ";
if(diemTB<6.5) return " Trung Binh ";
if(diemTB<8) return " Kha ";
if(diemTB<9) return " Gioi ";
return " xuat sac ";
}
public String toString() {
return maSV + ", " + hoTen + ", " + (gioiTinh?" Nam ":" Nu ")
+ ", " + diemTB + xepLoai();
}
public SinhVien() {
}
public SinhVien(String ma, String ht, boolean gt, double diem) {
maSV = ma;
hoTen = ht;
gioiTinh = gt;
diemTB = diem;
}
public String getMaSV() {
return maSV;
}
public void setMaSV(String ma) {
maSV = ma;
}
public String getHoTen() {
return hoTen;
}
public void setHoTen(String ht) {
hoTen = ht;
}
public boolean isGioiTinh() {
return gioiTinh;
}
public void setGioiTinh(boolean gt) {
gioiTinh = gt;
}
public double getDiemTB() {
return diemTB;
}
public void setDiemTB(double diem) {
diemTB = diem;
}
}
public class MangSinHVien {
private ArrayList a= new ArrayList();
public void input(){
int n;
Scanner kb = new Scanner(System.in);
System.out.print("Nhap so sinh vien >0:");
n = kb.nextInt();
for(int i=1; i<=n; i++){
SinhVien x = nhap1SinhVien("Nhap sinh vien thu "+i+": ");
a.add(x);
}
}
public SinhVien nhap1SinhVien(String cauDan){
System.out.print(cauDan);
String ma, ht;
boolean gt;
double diem;
Scanner kb = new Scanner(System.in);
ma = kb.next();
gt =kb.nextBoolean();
diem = kb.nextDouble();
ht = kb.nextLine();
return new SinhVien(ma, ht, gt, diem);
}
public void xuat(String cauDan){
System.out.println(cauDan);
for(SinhVien x: a)
System.out.println(x);
}
public void output(){
xuat("DS SV vua nhap ");
}
public static void main(String[] args) {
MangSinHVien x= new MangSinHVien();
x.input();
x.output();
}
}
// out put
run:
Nhap so sinh vien >0:2
Nhap sinh vien thu 1: sv001 true 8 Le Van Nam
Nhap sinh vien thu 2: sv002 false 9 Nguyen Thi Be
DS SV vua nhap
sv001, Le Van Nam, Nam , 8.0 Gioi
sv002, Nguyen Thi Be, Nu , 9.0 xuat sac