BT

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

QLSV TT: -s bo danh -ho tn -a ch -mn hc -im k1 -im k2 Phng Thc -Nhp Thng Tin -Xem Thng Tin

-Tm sinh vin Theo im -Cap nhat sinh vin -Xa Sinh Vin -kt Thc import java.util.*; import java.io.*; class SinhVien { private int sbd; private String names; private String adress; private String mh; private float dk1; private float dk2; public int getsbd() { return sbd; } public String getname() { return names; } public String getadress() { return adress; } public String getmh() { return mh; } public float getdk1() { return dk1; } public float getdk2() { return dk2; } public void Nhap() { try { Scanner scan =new Scanner(System.in); System.out.print("Nhap so bao danh:"); sbd =Integer.parseInt(scan.nextLine()); System.out.print("Nhap ho ten:"); names =scan.nextLine();

System.out.print("Nhap dia chi:"); adress=scan.nextLine(); System.out.print("Nhap mon hoc:"); mh=scan.nextLine(); System.out.print("Nhap diem ky 1:"); dk1=Float.parseFloat(scan.nextLine()); System.out.print("Nhap diem ky 2:"); dk2=Float.parseFloat(scan.nextLine()); }catch(Exception e) { System.out.print("Error"+e); } } public void Xuat() { try { System.out.println("THONG TIN SINH VIEN"); System.out.printf("%d\t%s\t%s\t%s\t%f\t%f",this.getsbd() ,this.getname(),this.getadress(),this.getmh(),this.getdk1(),this.getdk2()); }catch(Exception e) { System.out.print("Error"+e); } } } class DSSV extends SinhVien { public SinhVien[] listsv ; public int n; public DSSV() { n=0; listsv =new SinhVien[n]; } public int menu() { int c=0; try { System.out.println("QUAN LY SINH VIEN"); System.out.println("1.Nhap Thong Tin Sinh Vien"); System.out.println("2.Hien Thi Sinh Vien"); System.out.println("3.Tim Kiem Sinh Vien"); System.out.println("4.Cap Nhat Sinh Vien"); System.out.println("5.Xoa Sinh Vien"); System.out.println("0.Thoat"); System.out.println("Chon Phuong An:"); do{ Scanner scan =new Scanner(System.in); c=Integer.parseInt(scan.nextLine()); }while(c<0 || c>5); }catch(Exception e) { System.out.println("Error"+e); } return c; } public void AddStudent() {

try { Scanner scan =new Scanner(System.in); System.out.println("Nhap so luong sinh vien:"); n=Integer.parseInt(scan.nextLine()); listsv =new SinhVien[n]; for(int i=0;i<n;i++) { System.out.printf("\nThong Tin Sinh Vien Thu %d" ,(i+1)); listsv[i]=new SinhVien(); listsv[i].Nhap(); } }catch(Exception e) { System.out.println("Error"+e); } } public void Display() { try { for(int i=0;i<n;i++) { listsv[i].Xuat(); } }catch(Exception e) { System.out.print("Error"+e); } } public void SreachStudent() { try { Scanner scan =new Scanner(System.in); System.out.print("Nhap vao diem ky 1/ky 2"); float x=Float.parseFloat(scan.nextLine()); int flag=0; for(int i=0;i<n;i++) { if((x==listsv[i].getdk1()) || (x==listsv[i].getd k2())) { listsv[i].Xuat(); flag=1; } } if(flag==0) { System.out.println("Khong co sinh vien!"); } }catch(Exception e) { System.out.println("Error"+e); } } public void UpdateStudent() { try

{ Scanner scan =new Scanner(System.in); System.out.print("Nhap sbd sinh vien can sua:"); int bd =Integer.parseInt(scan.nextLine()); int flag=0; for(int i=0;i<n;i++) { if(bd==listsv[i].getsbd()) { listsv[i].Nhap(); flag=1; } } if(flag==0) { System.out.println("So Bao Danh khong hop le!"); } }catch(Exception e) { System.out.println("Error"+e); } } public void DeleteStudent() { try { Scanner scan=new Scanner(System.in); System.out.print("Nhap vao so bao danh:"); int sb=Integer.parseInt(scan.nextLine()); int flag=0; int vt=0; for(int i=0;i<n;i++) { if(sb==listsv[i].getsbd()) { vt=i; flag=1; break; } } for(int i=vt;i<n-1;i++) { listsv[i]=listsv[i+1]; } n--; if(flag==1) { System.out.println("delete ok, enter 2 watch vie w!!"); } else System.out.println("Delete that bai"); }catch(Exception e) { System.out.println("Error"+e); } } } public class QLSV { public static void main(String[] args)

{ DSSV k=new DSSV(); try { int ch; do { ch=k.menu(); switch(ch) { case 1:k.AddStudent();break; case 2:k.Display();break; case 3:k.SreachStudent();break; case 4:k.UpdateStudent();break; case 5:k.DeleteStudent();break; case 0:System.exit(0); default:System.out.println("please choice 0 to 5 ");break; } }while(ch!=0); }catch(Exception e) { System.out.println("Error"+e); } } }

You might also like