Created
April 12, 2012 10:05
-
-
Save ngnguyen1/2366197 to your computer and use it in GitHub Desktop.
Qly Sinh Vien
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package qlysv; | |
public class Main { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
int n,a=0,b=0,c=0; | |
System.out.print("So luong thi sinh: "); | |
n=NhapDL.nhapInt(); | |
KhoiA TSA[]=new KhoiA[n]; | |
KhoiB TSB[]=new KhoiB[n]; | |
KhoiC TSC[]=new KhoiC[n]; | |
System.out.println("--------NHAP THONG TIN---------"); | |
for(int j=0;j<n;j++) | |
{ int KhoiThi=TuyenSinh.nhapKT(); | |
switch (KhoiThi) | |
{ | |
case 1: | |
TSA[a]=new KhoiA("Toan","Ly","Hoa"); | |
TuyenSinh.Nhapts(TSA[a]); | |
a++; | |
break; | |
case 2: | |
TSB[b]=new KhoiB("Toan","Hoa","Sinh"); | |
TuyenSinh.Nhapts(TSB[b]); | |
b++; | |
break; | |
case 3: | |
TSC[c]=new KhoiC("Van","Su","Dia"); | |
TuyenSinh.Nhapts(TSC[c]); | |
c++; | |
break; | |
default: System.out.println(); | |
} | |
} | |
System.out.println("----------HIEN THI------"); | |
for(int j=0;j<n;j++) | |
{ | |
if (TSA[j]!=null) | |
TuyenSinh.OutputData(TSB[j]); | |
else | |
System.out.println("Khong co sinh vien khoi A"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package qlysv; | |
import java.io.*; | |
public class NhapDL | |
{ | |
static DataInputStream str=new DataInputStream(System.in); | |
public static String nhapchuoi() | |
{ | |
String st=""; | |
try { | |
st=str.readLine(); | |
}catch(Exception e){ | |
System.out.println("Loi" +e); | |
} | |
return st; | |
} | |
public static int nhapInt() | |
{ | |
String st=NhapDL.nhapchuoi(); | |
int i=0; | |
try{ | |
i=Integer.valueOf(st).intValue(); | |
}catch(Exception e){ | |
System.out.println("Loi" +e); | |
} | |
return i; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package qlysv; | |
public class ThiSinh { | |
protected String sHoTen, sDiaChi, sUT; | |
protected int iSoBD; | |
public ThiSinh() | |
{} | |
} | |
public class KhoiA extends ThiSinh{ | |
protected String sMon1,sMon2,sMon3; | |
KhoiA() | |
{} | |
KhoiA(String m1,String m2,String m3) | |
{ | |
sMon1=m1; | |
sMon2=m2; | |
sMon3=m3; | |
} | |
} | |
public class KhoiB extends KhoiA { | |
KhoiB() | |
{} | |
KhoiB(String m1,String m2,String m3) | |
{ | |
sMon1=m1; | |
sMon2=m2; | |
sMon3=m3; | |
} | |
} | |
public class KhoiC extends KhoiA{ | |
KhoiC() | |
{} | |
KhoiC(String m1,String m2,String m3) | |
{ | |
sMon1=m1; | |
sMon2=m2; | |
sMon3=m3; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package qlysv; | |
public class TuyenSinh { | |
public static void Nhapts(ThiSinh ts) | |
{ | |
System.out.print("SBD: "); | |
ts.iSoBD=NhapDL.nhapInt(); | |
System.out.print("Ho va ten: "); | |
ts.sHoTen=NhapDL.nhapchuoi(); | |
System.out.print("Dia Chi: "); | |
ts.sDiaChi=NhapDL.nhapchuoi(); | |
System.out.print("Uu tien: "); | |
ts.sUT=NhapDL.nhapchuoi(); | |
} | |
public static void OutputData(KhoiA ts) | |
{ | |
System.out.println("------------------"); | |
System.out.println("SBD: " +ts.iSoBD); | |
System.out.println("Ho va ten: " +ts.sHoTen); | |
System.out.println("Dia Chi: " +ts.sDiaChi); | |
System.out.println("Uu tien: " +ts.sUT); | |
System.out.println("Mon 1: " +ts.sMon1); | |
System.out.println("Mon 2: " +ts.sMon2); | |
System.out.println("Mon 3: " +ts.sMon3); | |
} | |
public static boolean ssXau(String st1,String st2) | |
{ | |
if(st1.equalsIgnoreCase(st2)) return false; | |
else return true; | |
} | |
public static int nhapKT() | |
{ | |
String kt; | |
System.out.print("Khoi thi: "); | |
do{ | |
kt=NhapDL.nhapchuoi(); | |
if(ssXau(kt,"A")&&(ssXau(kt,"B"))&&(ssXau(kt,"C"))) | |
System.out.println("Ban chi co the nhap A or B or C"); | |
}while(ssXau(kt,"A")&&ssXau(kt,"B")&&ssXau(kt,"C")); | |
if (ssXau(kt,"A")==false) return 1; | |
else | |
if (ssXau(kt,"B")==false) return 2; | |
else | |
if (ssXau(kt,"C")==false) return 3; | |
else return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment