Đáp Án Đề 4 : Tuyển Sinh




Tuyển Sinh

  Các thí sinh dự thi đại học bao gồm các thí sinh thi khối A, thí sinh thi khối B, thí sinh thi khối C
  + Các thí sinh cần quản lý các thuộc tính: Số báo danh, họ tên, địa chỉ, diện ưu tiên khu vực.
  + Thí sinh thi khối A thi các môn: Toán, lý, hoá
  + Thí sinh thi khối B thi các môn: Toán, Hoá, Sinh
  + Thí sinh thi khối C thi các môn: Văn, Sử, Địa

 1. Xây dựng các lớp để quản lý các thí sinh sao cho sử dụng lại được nhiều nhất.
 2. Xây dựng lớp TuyenSinh cài đặt các phương thức thực hiện các nhiệm vụ sau:
  - Nhập thông tin về các thí sinh dự thi
  - Hiển thị thông tin về một thí sinh
  - Tìm kiếm theo số báo danh


 //Lop KhoiA
import java.util.Scanner;
public class KhoiA extends ThiSinh
{
    protected String mon1;
    protected String mon2;
    protected String mon3;
    
    public KhoiA(){}
        
    public KhoiA(String mon1, String mon2, String mon3){
        this.mon1 = mon1;
        this.mon2 = mon2;
        this.mon3 = mon3;
    }
    
    public void inThongTin(){
        super.inThongTin();
        System.out.println("Mon 1: " + this.mon1);
        System.out.println("Mon 2: " + this.mon2);
        System.out.println("Mon 3: " + this.mon3);
    }
}
//Lop KhoiB
import java.util.Scanner;

public class KhoiB extends KhoiA
{
    public KhoiB(){}
    
    public KhoiB(String mon1, String mon2, String mon3){
        super(mon1,mon2,mon3);
    }
}
//Lop KhoiC
import java.util.Scanner

public class KhoiC extends KhoiA
{
    public KhoiC(){}
    
    public KhoiC(String mon1, String mon2, String mon3){
        super(mon1,mon2,mon3);
    }
}
//Lop ThiSinh
import java.util.Scanner;

public class ThiSinh
{
    protected String hoTen;
    protected int sbd;
    protected String diaChi;
    protected String uuTien;
    
    public ThiSinh(){}
    
    public ThiSinh(String hoTen, int sbd, String diaChi, String uuTien){
        this.hoTen = hoTen;
        this.sbd = sbd;
        this.diaChi = diaChi;
        this.uuTien = uuTien;
    }
    
    public void nhapThongTin(Scanner sc){
        System.out.print("Nhap ho ten: ");
        this.hoTen = sc.nextLine();
        System.out.print("Nhap so bao danh: ");
        this.sbd = sc.nextInt(); sc.nextLine();
        System.out.print("Nhap dia chi: ");
        this.diaChi = sc.nextLine();
        System.out.print("Nhap uu tien: ");
        this.uuTien = sc.nextLine();
    }
    
    public void inThongTin(){
        System.out.println("Ho ten: " + this.hoTen);
        System.out.println("So bao danh: " + this.sbd);
        System.out.println("Dia chi: " + this.diaChi);
        System.out.println("Khu vuc uu tien: " + this.uuTien);
    }
}
//Lop TuyenSinh
import java.util.ArrayList;
import java.util.Scanner;

public class TuyenSinh
{
    private ArrayList<ThiSinh> dsts;
    
    public TuyenSinh(){
        dsts = new ArrayList<ThiSinh>(100);
    }
    
    public void nhapDsDuThi(Scanner sc){
        String traLoi;
        int chon;
        ThiSinh ts;
        
        do{
            System.out.print("Nhap thi sinh(1-Khoi A, 2-Khoi B, 3-KhoiC): ");
            chon = sc.nextInt(); sc.nextLine();
            
            switch(chon){
                case 1:
                    ts = new KhoiA("Toan", "Ly", "Hoa");
                    break;
                case 2:
                    ts = new KhoiB("Toan", "Hoa", "Sinh");
                    break;
                case 3:
                    ts = new KhoiC("Van", "Su", "Dia");
                    break;
                default:
                    ts = new KhoiA("Toan", "Ly", "Hoa");
                    break;
            }
            
            ts.nhapThongTin(sc);
            dsts.add(ts);//Them thi sinh da nhap vao danh sach
            
            System.out.print("Ban muon nhap nua khong? (c/k): ");
            traLoi = sc.nextLine();
        }while("c".equalsIgnoreCase(traLoi));
    }
    
    public void inDsDuThi(){
        for(ThiSinh ts : dsts){
            ts.inThongTin();
        }
    }
    
    public void timKiemTS(int sbd){
        for(ThiSinh ts : dsts){
            if(sbd == ts.sbd){
                ts.inThongTin();
            }
        }
    }
    
    public static void main(String[] args){
        TuyenSinh ts = new TuyenSinh();
        
        Scanner sc = new Scanner(System.in);
        
        System.out.println("Nhap danh sach thi sinh:");
        ts.nhapDsDuThi(sc);
        System.out.println("--------------------");
        
        System.out.println("Danh sach thi sinh da nhap la:");
        ts.inDsDuThi();
        System.out.println("--------------------");
        
        System.out.println("Thi sinh co so bao danh la 0001 la:");
        ts.timKiemTS(0001);// Truyền vào số báo danh cần tìm
    }
}



Đăng nhận xét

Cảm Ơn Bạn Đã Để Lại Bình Luận

 

Quản Trị Viên

Lượt xem

Lên Trên