-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainRun.java
More file actions
59 lines (48 loc) · 1.44 KB
/
Copy pathMainRun.java
File metadata and controls
59 lines (48 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package connnection;
import java.util.Scanner;
public class MainRun {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StudentManeger maneger = new StudentManeger();
System.out.print("Number student insert: ");
int numStudent = inputInteger(sc);
Student[] listStudent = new Student[numStudent];
for (int i = 0; i < listStudent.length; i++) {
System.out.println("Student " + (i + 1) + ": ");
System.out.print("Name: ");
sc.nextLine();
String name = sc.nextLine();
System.out.print("Gender: ");
String gender = sc.next();
System.out.print("Country: ");
sc.nextLine();
String country = sc.nextLine();
System.out.print("Age: ");
int age = inputInteger(sc);
listStudent[i] = new Student(name, gender, country, age);
System.out.println();
}
int count = 0;
for (int i = 0; i < listStudent.length; i++) {
if (maneger.insert(listStudent[i])) {
count++;
}
}
System.out.println("Thêm thành công " + count + " dữ liệu");
sc.close();
}
public static int inputInteger(Scanner sc) {
int reusult = 0;
boolean isValidInput = false;
while (!isValidInput) {
String input = sc.next();
try {
reusult = Integer.parseInt(input);
isValidInput = true;
} catch (NumberFormatException e) {
System.out.print("Phải là số nguyên vui lòng nhập lại: ");
}
}
return reusult;
}
}