Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Java by baolhq ( 8 years ago )
package baithuchanh2;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
/**
*
* @author baolhq
*/
public class Bai4 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean chayChuongTrinh = true;
while (chayChuongTrinh) {
inMenu();
System.out.print("Chon: ");
int chonChucNang = sc.nextInt();
switch (chonChucNang) {
case 0:
chayChuongTrinh = false;
break;
case 1:
int hocVienThu = TrungTamGiaSu.getDanhSachHocVien().size();
boolean nhapHocVien = true;
while (nhapHocVien) {
System.out.print("Ban co muon nhap (Y/N): ");
String traLoi = sc.next();
if (traLoi.equalsIgnoreCase("N")) {
nhapHocVien = false;
} else if (traLoi.equalsIgnoreCase("Y")) {
System.out.printf("Nhap thong tin hoc vien thu %d:\n", hocVienThu + 1);
HocVien hocVien = new HocVien();
hocVien.nhap(sc);
if (!TrungTamGiaSu.getDanhSachHocVien().add(hocVien)) {
System.out.println("Co loi da xay ra khi nhap!");
} else {
System.out.printf("Nhap thanh cong hoc vien thu %d\n", hocVienThu + 1);
hocVienThu++;
}
}
}
break;
case 2:
System.out.println("\n========== Danh sach hoc vien ==========");
for (int i = 0; i < TrungTamGiaSu xss=removed xss=removed xss=removed xss=removed xss=removed xss=removed xss=removed xss=removed xss=removed xss=removed xss=removed xss=removed xss=removed xss=removed xss=removed xss=removed xss=removed xss=removed> DanhSachHocVien = new LinkedList<HocVien>();
public static void danhSachHocVienTot() {
for (HocVien hocVien : DanhSachHocVien) {
if (hocVien.coTot()) {
System.out.println(hocVien);
}
}
}
public static HocVien timHocVien_QueQuan(String queQuanTim) {
HocVien hocVienTim = null;
for (HocVien hocVien : DanhSachHocVien) {
if (hocVien.getQueQuan().equalsIgnoreCase(queQuanTim)) {
hocVienTim = hocVien;
break;
}
}
return hocVienTim;
}
public static HocVien timHocVien(String hoTenTim) {
HocVien hocVienTim = null;
for (HocVien hocVien : DanhSachHocVien) {
if (hocVien.getHoTen().equalsIgnoreCase(hoTenTim)) {
hocVienTim = hocVien;
break;
}
}
return hocVienTim;
}
public static HocVien timHocVien(int maSoTim) {
HocVien hocVienTim = null;
for (HocVien hocVien : DanhSachHocVien) {
if (hocVien.getMaSoHocVien() == maSoTim) {
hocVienTim = hocVien;
break;
}
}
return hocVienTim;
}
/**
* @return the danhSachHocVien
*/
public static List<HocVien>getDanhSachHocVien() {
return DanhSachHocVien;
}
}
class HocVien {
private int maSoHocVien;
private String hoTen;
@SuppressWarnings("unused")
private int namSinh;
@SuppressWarnings("unused")
private String gioiTinh;
private String queQuan;
private double diemMon1, diemMon2, diemMon3;
public boolean coTot() {
boolean tot = false;
double diemTrungBinh = 0;
diemTrungBinh = (this.diemMon1 + this.diemMon2 + this.diemMon3) / 3;
tot = diemTrungBinh >= 8.0 && !(this.diemMon1 < 5.0 || this.diemMon2 < 5.0 || this.diemMon3 < 5.0);
return tot;
}
public void nhapDiem(Scanner sc) {
System.out.print("Nhap diem mon 1: ");
this.diemMon1 = sc.nextDouble();
System.out.print("Nhap diem mon 2: ");
this.diemMon2 = sc.nextDouble();
System.out.print("Nhap diem mon 3: ");
this.diemMon3 = sc.nextDouble();
}
public void nhap(Scanner sc) {
System.out.print("Nhap ma so: ");
this.maSoHocVien = sc.nextInt();
System.out.print("Nhap ho ten: ");
sc.nextLine();
this.hoTen = sc.nextLine();
System.out.print("Nhap nam sinh: ");
this.namSinh = sc.nextInt();
System.out.print("Nhap que quan: ");
sc.nextLine();
this.queQuan = sc.nextLine();
}
@Override
public String toString() {
return String.format("%d | %s", this.maSoHocVien, this.hoTen);
}
/**
* @return the maSoHocVien
*/
public int getMaSoHocVien() {
return this.maSoHocVien;
}
/**
* @return the hoTen
*/
public String getHoTen() {
return this.hoTen;
}
/**
* @param hoTen the hoTen to set
*/
public void setHoTen(String hoTen) {
this.hoTen = hoTen;
}
/**
* @return the queQuan
*/
public String getQueQuan() {
return this.queQuan;
}
}
Revise this Paste
Parent: 95267