-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudents.java
78 lines (60 loc) · 1.92 KB
/
Students.java
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author kdost
*/
public class Student {
private String name;
private String studentNumber;
public Student (String name, String studentNumber) {
this.name = name;
this.studentNumber = studentNumber;
}
public String getName() {
return this.name;
}
public String getStudentNumber() {
return this.studentNumber;
}
@Override
public String toString() {
return this.name + " (" + this.studentNumber + ")";
}
}
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// write here the main program
ArrayList<Student> list = new ArrayList<Student>();
Scanner reader = new Scanner(System.in);
String userInputName = "";
String userInputNumber = "";
String userInputSearch = "";
while (true) {
System.out.print("name: ");
userInputName = reader.nextLine();
if (userInputName.equals("")) {
break;
}
System.out.print("student number: ");
userInputNumber = reader.nextLine();
list.add(new Student(userInputName, userInputNumber));
}
for (Student stu : list) {
System.out.println(stu.getName() + " (" + stu.getStudentNumber() + ")");
}
System.out.println("Give search term:");
userInputSearch = reader.nextLine();
for (Student stu : list) {
if (stu.getName().contains(userInputSearch)) {
System.out.println("Result: ");
System.out.println(stu.toString());
}
}
}
}