Your SlideShare is downloading. ×
Bai day1
Bai day1
Bai day1
Bai day1
Bai day1
Bai day1
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
83
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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. 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. 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. 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. 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. 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; } }

×