asian xxxx
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package quanly;
import java.io.Serializable;
import java.util.Scanner;
/**
*
* @author menguyen
*/
public class MonHoc implements Serializable{
protected int MaMH;
protected String TenMH;
protected int Loai;
protected int SoDVHT;
public MonHoc() {
}
MonHoc(int MaMH, String TenMH, int Loai, int SoDVHT){
this.MaMH=MaMH;
this.TenMH=TenMH;
this.Loai=Loai;
this.SoDVHT=SoDVHT;
}
public void nhap(){
Scanner in=new Scanner(System.in);
System.out.println("Ten Mon hoc");TenMH=in.nextLine();
System.out.println("Loai:");Loai=Integer.parseInt(in.nextLine());
while(Loai<1||Loai>3){
System.out.println("Nhap lai");
Loai=Integer.parseInt(in.nextLine());
}
System.out.println("So DVHT:");SoDVHT=Integer.parseInt(in.nextLine());
}
public void xuat(){
System.out.println("Ten Mon hoc:"+TenMH);
System.out.println("Loai");
switch(Loai){
case 1: System.out.println("Dai cuong");
case 2: System.out.println("Co so Nganh");
case 3: System.out.println("Chuyen Nganh");
}
System.out.println("So dvht:"+SoDVHT);
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package quanly;
/**
*
* @author menguyen
*/
public class Nguoi {
protected String HoTen;
protected String DiaChi;
Nguoi(){};
public Nguoi(String HoTen, String DiaChi){
this.DiaChi=DiaChi;
this.HoTen=HoTen;
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package quanly;
import java.io.*;
import java.util.*;
/**
*
* @author menguyen
*/
public class QuanLy {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException, ClassNotFoundException{
Scanner in= new Scanner(System.in);
System.out.println("Nhap thong tin Sinh Vien");
System.out.println("-------------------------------------------------------");
ObjectOutputStream obj= new ObjectOutputStream(new FileOutputStream("sv.in"));
for (int i=0;i<5;i++){
SinhVien sv= new SinhVien();
sv.nhap();
obj.writeObject(sv);
}
System.out.println("In thong tin sv:");
System.out.println("--------------------------------------------------------");
ObjectInputStream obj1= new ObjectInputStream(new FileInputStream("sv.in"));
for (int i=0;i<5;i++){
SinhVien sv;
sv= (SinhVien) obj1.readObject();
sv.xuat();
}
System.out.println("Nhap thong tin Mon hoc:");
System.out.println("---------------------------------------------------------");
ObjectOutputStream obj2= new ObjectOutputStream(new FileOutputStream("MH.in"));
for(int i=0;i<3;i++){
MonHoc mh= new MonHoc();
mh.nhap();
obj.writeObject(mh);
}
System.out.println("In thong tin mon hoc");
System.out.println("----------------------------------------------------------");
ObjectInputStream obj3= new ObjectInputStream(new FileInputStream("mh.in"));
for(int i=0;i<3;i++){
MonHoc mh;
mh= (MonHoc) obj3.readObject();
mh.xuat();
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package quanly;
import java.io.Serializable;
import java.util.Scanner;
/**
*
* @author menguyen
*/
public class SinhVien extends Nguoi implements Serializable{
protected int MaSV;
protected int Loai;
protected String Lop;
static int i=0;
SinhVien(){MaSV=i;i++;};
public SinhVien(int MaSV, int Loai, String Lop){
this.MaSV=MaSV;
this.Loai=Loai;
this.Lop=Lop;
};
public void nhap(){
Scanner in= new Scanner(System.in);
System.out.println("Ho Ten SV:");HoTen=in.nextLine();
System.out.println("Dia chi:");DiaChi= in.nextLine();
// System.out.println("Loai:");Loai=Integer.parseInt(in.nextLine());
System.out.println("Lop:"); Lop=in.nextLine();
System.out.println("Loai");Loai=in.nextInt();
while(Loai<1||Loai>3){
System.out.println("nhap lai");
Loai=in.nextInt();
}
}
public void xuat(){
System.out.println("Ho Ten: "+HoTen);
System.out.println("Dia Chi"+DiaChi);
System.out.println("Lop"+Lop);
System.out.println("Loai");
switch(Loai){
case 1: System.out.println("chinh quy");break;
case 2: System.out.println("Tai chuc");break;
case 3: System.out.println("Tu xa");break;
}
}
}
Bạn đang đọc truyện trên: AzTruyen.Top