0% found this document useful (0 votes)
16 views11 pages

Savior

Uploaded by

c5r6b4hqbr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views11 pages

Savior

Uploaded by

c5r6b4hqbr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Lớp student this.

khoaHoc =

khoaHoc;
public class HocSinh extends Nguoi {

}
private String lop;

public String getLop() { return


private String khoaHoc;
lop;}

private int kyHoc;


//cài đè, gọi lại để nhập thêm tt

public HocSinh() {} về quê quán vv...

public HocSinh(String hoTen, Date ngaySinh, @Override

String lop, String khoaHoc) {


public void nhapThongTin(Scanner sc) {
super(hoTen,ngaySinh);

this.lop = lop;
super.nhapThongTin(sc);

this.khoaHoc =
System.out.print("nhap lop: ");
khoaHoc;

lop = sc.nextLine();
}

System.out.print("nhap khoa hoc: ");


public HocSinh(String hoTen, String lop, String

khoaHoc) { khoaHoc = sc.nextLine();

this.hoTen = hoTen;

this.lop = lop; Scanner sc = new

System.out.print("nhap
ky hoc: "); Scanner(System.in);

kyHoc = sc.nextInt(); sc.nextLine(); hs.nhapThongTin(sc);

} hs.inThongTin();

@Override }

public void inThongTin() {

super.inThongTin();

System.out.println(lop);

System.out.println(khoaHoc);

System.out.println(kyHoc);}

public static void main(String[] args) {

HocSinh hs = new HocSinh();

Lớp người this(hoTen,ngaySinh);


import java.util.Date; this.queQuan = queQuan;}

import java.util.Scanner; public void nhapThongTin(Scanner sc) {

import java.text.ParseException; System.out.print("Nhap ho ten:

");
import java.text.SimpleDateFormat;

hoTen=sc.nextLine();
public class Nguoi {

System.out.print("Nhap ngay
protected String hoTen;
sinh: ");

protected Date ngaySinh;


String ngaySinhstr = sc.nextLine();

protected String queQuan;


ngaySinh = stringToDate(ngaySinhstr);

public Nguoi() {}
System.out.println("nhap que quan: ");

queQuan = sc.nextLine();}

public Nguoi(String hoTen, Date ngaySinh) {


private Date stringToDate(String

this.hoTen = hoTen; ngaySinhstr) {

this.ngaySinh = ngaySinh; } Date ngaySinhDate = null;

public Nguoi(String hoTen, Date ngaySinh, String public static void main(String[] args)

queQuan) { {

SimpleDateFormat sdf = new


SimpleDateFormat("dd/MM/yyyy"); Nguoi ng = new Nguoi();

try {ngaySinhDate = sdf.parse(ngaySinhstr); Scanner sc = new

Scanner(System.in);
} catch (ParseException e) {

ng.nhapThongTin(sc);
// TODO Auto-generated catch block

ng.inThongTin();
e.printStackTrace();

}
System.out.println("loi dinh dang");

}
}return ngaySinhDate;

public void inThongTin() {

System.out.println(hoTen);

System.out.println(ngaySinh);

System.out.println(queQuan);
Lớp student Scanner sc = new Scanner(System.in);

import java.util.Scanner; sv.nhapThongTin(sc);

public class SinhVien extends Nguoi { sv.inThongTin();

private String msv; }

public SinhVien() { }

public SinhVien(String hoTen, String msv) {

this.hoTen = hoTen;

this.msv = msv;

public void nhapThongTin(Scanner sc) {

System.out.println("nhap thong tin sinh vien");

System.out.println("nhap msv: ");

msv = sc.nextLine();

super.nhapThongTin(sc);

public void inThongTin() {

super.inThongTin();

System.out.println(msv);

public String getMsv() {

return msv;

public static void main(String[] args) {

SinhVien sv = new SinhVien();


QLHS public void inDanhSach() {

public class QLHS { for(HocSinh hs : dshs) {

private ArrayList<HocSinh> hs.inThongTin();}

dshs;
}

public QLHS() {
public void timKiemHocSinh(int namSinh, String queQuan) {

dshs = new
System.out.println("Danh sach hs sinh nam" + namSinh + "que o "
ArrayList<HocSinh>();
+ queQuan + ":");

}
for (HocSinh hs : dshs) {

public void themHocSinh(HocSinh hs) {


if((namSinh==hs.ngaySinh.getYear()+1900)

dshs.add(hs);
&&(queQuan.equals(hs.queQuan))){

}
hs.inThongTin();}}}

public void nhapDanhSach(Scanner sc) {


public void timKiemHocSinh(String lop) {

System.out.println("nhap so
System.out.println("Nhap DS hoc sinh cua lop " + lop + ":");
luong hoc sinh: ");

for (HocSinh hs : dshs) {


int n = sc.nextInt();sc.nextLine();

if(lop.equals(hs.getLop())) {
for(int i=0; i<n; i++) {

hs.inThongTin();
HocSinh hs = new HocSinh();

}} }
hs.nhapThongTin(sc);

themHocSinh(hs);}}
public static void main(String[] args) {

QLHS hs = new

QLHS();

Scanner sc= new

Scanner(System.in);

hs.nhapDanhSach(sc);

hs.inDanhSach();

hs.timKiemHocSinh(2004, "hn");

System.out.println("--------------------------

------");

hs.timKiemHocSinh("cnpma");

}
QLNS sc.nextLine();

import java.util.ArrayList;import java.util.List;import int chon = 0;

java.util.Scanner;
Nguoi ns = null;

public class QLNS {


for (int i = 0; i < n; i++)

private List<Nguoi> dsns; {System.out.println("chọn loại bạn muốn

nhập(0: hs, 1:sv): ");


public QLNS() {

chon = sc.nextInt();sc.nextLine();
dsns = new

ArrayList<Nguoi>(100); switch (chon) {

//nguoi: kieu du lieu(<>),(100) case 0:

so phan tu.
ns = new HocSinh();

}
break;

case 1:
public void themNhanSu(Nguoi ns) {
ns = new SinhVien(); break;
dsns.add(ns);
default: System.out.println("lua chon ko
} hop le, vui long chon lai");

public void nhapDanhSach(Scanner sc) { continue;}

System.out.println("nhap so nhan su n = ns.nhapThongTin(sc);themNhanSu(ns);}


");
}
int n = sc.nextInt();

public void inDanhSach() {


public static void main(String[] args)
//for (ElementType element : collection) { {

// collection là tập hợp các phần tử mà bạn muốn lặp QLNS qlns = new QLNS();
BÀI TEST public void addCourse(String TenMH, int Diem) {

public class Person { Courses[numCourses] = TenMH;

private String name; grades[numCourses] = Diem;

private String address; numCourses++;

public Person() {} }

public Person(String name, String address) { public double getAverageGrade() {

super(); int sum = 0;

this.name = name; for(int i=0; i<numCourses;i++) {

this.address = address; sum = sum + grades[i];

} }

public String getName() { double avg = (double)sum/numCourses;

return name; return avg;}}

} package baiThiThu;

public String getAddress() { public class main {

return address;}} public static void main(String[] args) {

LỚP STUDENT // TODO Auto-generated method stub

public class Student extends Person{ Student st = new Student("Nguyen Thanh Nam", "Trau
Quy - Gia Lam");
private int numCourses;
st.addCourse("Java", 9);
private String[] Courses = new String[10];
st.addCourse("CSDL", 8);
private int[] grades = new int[10];
st.addCourse("Pascal", 10);
public Student(String name, String address) {
st.addCourse("Network", 6);
super(name, address);
System.out.println(st.toString());
}
System.out.println(st.getAverageGrade());
@Override
}
public String toString() {return "Student: " + getName() +
"(" + getAddress() + ")";} }

You might also like