Upcoming SlideShare
×

# Bai day1

282 views
160 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
282
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
5
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Bai day1

1. 1. import java.util.ArrayList; import java.util.Random; public class day1 { // random ten public static int[] randomTen(int num, int sum) { int count = 0; boolean flag; int[] arrNum = new int[num]; Random random = new Random(); int value; while (count < num) { flag = false; value = random.nextInt(sum); for (int i = 0; i < arrNum.length; i++) { if (arrNum[i] == value) { flag = true; break; } } if (!flag) { arrNum[count] = value; count++; } } return arrNum; } //random ma so public static int[] randomMaso(int num, int sum) { int count = 0; boolean flag; int[] arrNum = new int[num]; Random random = new Random(); int value; while (count < num) { flag = false; value = random.nextInt(sum-1000000)+1000000; for (int i = 0; i < arrNum.length; i++) { if (arrNum[i] == value) { flag = true; break; } } if (!flag) { arrNum[count] = value; count++; } } return arrNum; } //random 1 so public static int RandomSize(int index) { int numRan = 0; Random random = new Random(); numRan = random.nextInt(index); return numRan; } //ham tao ngay sinh public static String[] day() { String[]date= new String[25];
2. 2. Random random = new Random(); int m ; int d =1; for (int i = 0; i < date.length; i++) { m = random.nextInt(12-1)+1; switch (m) { case 1:case 3:case 5:case 7:case 8:case 10:case 12: d = random.nextInt(31-1)+1; break; case 4: case 6: case 9: case 11: d= random.nextInt(30-1)+1; break; case 2: d=random.nextInt(29-1+1); break; } date[i] = "" + m +""+d+"1991"; } return date; // } Diem public static int[] diemMonHoc() { int[]arrdiem = day1.randomTen(25, 26); return arrdiem; } public static void main(String[] args) { String[] ho = { "Tra", "Phan", "Pham", "Do", "Le", "Trinh", "Nguyen", "Huynh" }; "Thu", "Mai", "Van", "Nhat" }; "Cuc", "Dung", "Tap", "Truc", "Phap", "Ly", "Mac", "Ong", "Ma", "Che", "Ha", "Chau", String[] dem = { "Mai", "Kim", "Quynh", "Quang", "Thanh", "Thi", "Xuan", "Duc", "Nhat", "Vinh", "Le", "Hong", "Anh", "Cong", "Xuan", "Ha", "Thu", "Dong", "Chang", "Mau", "Minh", "Quoc", "Truong", "Chi", "Vinh", "Tien", String[] ten = { "Dong", "Tay", "Nam", "Bac", "Hong", "Buoi", "Dao", "Man", "Quyt", "Oi", "Nho", "Me", "Soai", "Coc", "Lan", "Nhung", "Mai", "Dao", "Tho", "Sinh", "Hung", "Trong", "Nhan", "Triet", "Phuc", "Thang", "Yen", "Dam", "Muoi", "Long", "Ho", "Bao", "Chon", "Meo", "Chuot", "Vuon", "Phuong", "Tinh", "Viet", "Duc", "Ao", "CuBa", "Anh", "Y", "Bi" }; int[] arrInt = day1.randomTen(25, 50); int[] arrMaso = day1.randomMaso(25, 9999999); String[] hotenSv = new String[25]; String[] maso = new String[25]; String[] date = day1.day(); ArrayList<SinhVien> SinhVien = new ArrayList<>(); day1.diemMonHoc();
3. 3. int[] int[] int[] int[] int[] diemMon1 diemMon2 diemMon3 diemMon4 diemMon5 = = = = = day1.diemMonHoc(); day1.diemMonHoc(); day1.diemMonHoc(); day1.diemMonHoc(); day1.diemMonHoc(); for (int i = 0; i < hotenSv.length; i++) { hotenSv[i] = "" + ho[RandomSize(ho.length)] + " "+ dem[RandomSize(dem.length)] + " " + ten[arrInt[i]]; maso[i] ="HV"+arrMaso[i]; SinhVien sv = new SinhVien(); sv.setHoTen(hotenSv[i]) ; sv.setMaSo(maso[i]); sv.setNgaySinh(date[i]); for (int j = 0; j < diemMon1.length; j++) { if (j<=2 && i==diemMon1[j]) { sv.setDiem1(((int)Math.random()*10+8)); } else if(j>2 && j<=15 && i==diemMon1[j]){ sv.setDiem1(5); } else if (j>15 && j<=21 && i==diemMon1[j]) { sv.setDiem1(3); } else if (j>21 && j<=24 && i==diemMon1[j]) { sv.setDiem1(1); } } for (int j = 0; j < diemMon2.length; j++) if (j<=2 && i==diemMon2[j]) { sv.setDiem2(8); } else if(j>2 && j<=15 && i==diemMon2[j]){ sv.setDiem2(5); } else if (j>15 && j<=21 && i==diemMon2[j]) sv.setDiem2(3); } else if (j>21 && j<=24 && i==diemMon2[j]) sv.setDiem2(1); } } for (int j = 0; j < diemMon1.length; j++) if (j<=2 && i==diemMon1[j]) { sv.setDiem3(8); } else if(j>2 && j<=15 && i==diemMon1[j]){ sv.setDiem3(5); } else if (j>15 && j<=21 && i==diemMon1[j]) sv.setDiem3(3); } else if (j>21 && j<=24 && i==diemMon1[j]) sv.setDiem3(1); } } for (int j = 0; j < diemMon1.length; j++) if (j<=2 && i==diemMon1[j]) { sv.setDiem4(8); } else if(j>2 && j<=15 && i==diemMon1[j]){ { { { { { { {
4. 4. sv.setDiem4(5); } else if (j>15 && j<=21 && i==diemMon1[j]) sv.setDiem4(3); } else if (j>21 && j<=24 && i==diemMon1[j]) sv.setDiem4(1); } } for (int j = 0; j < diemMon2.length; j++) if (j<=2 && i==diemMon2[j]) { sv.setDiem2(8); } else if(j>2 && j<=15 && i==diemMon2[j]){ sv.setDiem2(5); } else if (j>15 && j<=21 && i==diemMon2[j]) sv.setDiem2(3); } else if (j>21 && j<=24 && i==diemMon2[j]) sv.setDiem2(1); } } SinhVien.add(sv); { { { { { } for (int i = 0; i < SinhVien.size(); i++) { System.out.println(SinhVien.get(i).getHoTen()+" "+SinhVien.get(i).getMaSo()+" "+SinhVien.get(i).getNgaySinh() +" "+SinhVien.get(i).getDiem1()+" "+SinhVien.get(i).getDiem2()+ " "+SinhVien.get(i).getDiem3() ); } } } ======================================================================= public class SinhVien { private private private private private private private private private String hoTen; String MaSo; String ngaySinh; int diem1; int diem2; int diem3; int diem4; int diem5; float diemtB; public float getDiemtB() { return diemtB; } public void setDiemtB(float diemtB) { this.diemtB = diemtB; } public String getHoTen() { return hoTen; } public void setHoTen(String hoTen) { this.hoTen = hoTen; }
5. 5. public String getMaSo() { return MaSo; } public void setMaSo(String maSo) { MaSo = maSo; } public String getNgaySinh() { return ngaySinh; } public void setNgaySinh(String ngaySinh) { this.ngaySinh = ngaySinh; } public int getDiem1() { return diem1; } public void setDiem1(int diem1) { this.diem1 = diem1; } public int getDiem2() { return diem2; } public void setDiem2(int diem2) { this.diem2 = diem2; } public int getDiem3() { return diem3; } public void setDiem3(int diem3) { this.diem3 = diem3; } public int getDiem4() { return diem4; } public void setDiem4(int diem4) { this.diem4 = diem4; } public int getDiem5() { return diem5; } public void setDiem5(int diem5) { this.diem5 = diem5; } }
6. 6. public String getMaSo() { return MaSo; } public void setMaSo(String maSo) { MaSo = maSo; } public String getNgaySinh() { return ngaySinh; } public void setNgaySinh(String ngaySinh) { this.ngaySinh = ngaySinh; } public int getDiem1() { return diem1; } public void setDiem1(int diem1) { this.diem1 = diem1; } public int getDiem2() { return diem2; } public void setDiem2(int diem2) { this.diem2 = diem2; } public int getDiem3() { return diem3; } public void setDiem3(int diem3) { this.diem3 = diem3; } public int getDiem4() { return diem4; } public void setDiem4(int diem4) { this.diem4 = diem4; } public int getDiem5() { return diem5; } public void setDiem5(int diem5) { this.diem5 = diem5; } }