-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgeRange.java
More file actions
68 lines (60 loc) · 1.83 KB
/
AgeRange.java
File metadata and controls
68 lines (60 loc) · 1.83 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
60
61
62
63
64
65
66
67
68
public class AgeRange {
Person[] people;
int startAge;
int endAge;
AgeRange(int startAge, int endAge) {
this.startAge = startAge;
this.endAge = endAge;
}
public static void main(String[] args){
AgeRange program = new AgeRange(Integer.parseInt(args[0]), Integer.parseInt(args[1]));
program.addPersons(5);
program.output();
}
void addPersons(int personsCount) {
people = new Person[personsCount];
people[0] = new Person("Hein Ko Ko", 23, "Yangon", "heinko@gmail.com");
people[1] = new Person("Aung Htet Naing", 9, "Mandalay", "aunghtet@yahoo.com");
people[2] = new Person("Mya Kyay Hmon", 34, "Bago", "myakyay@gmail.com");
people[3] = new Person("Wutt Yee", 25, "Taung Gyi", "wuttyee@gmail.com");
people[4] = new Person("Naing Min Oo", 45, "Kalaw", "naingmin@gmail.com");
}
void output() {
System.out.println("\n---------------");
System.out.println("Search Result");
System.out.println("---------------");
generateResult();
System.out.println("-----END-----");
}
void generateResult() {
boolean found = false;
int j = 1;
for(int i = 0; i < this.people.length; i++){
if(this.people[i].age >= this.startAge && this.people[i].age <= this.endAge){
found = true;
this.people[i].show(j);
j++;
}
}
System.out.print(found ? "" : "-----NOT FOUND!!!-----\n");
}
}
class Person {
String name;
int age;
String address;
String email;
Person(String name, int age, String address, String email) {
this.name = name;
this.age = age;
this.address = address;
this.email = email;
}
void show(int no){
System.out.println("-----(" + no + ")-----");
System.out.println("name=" + this.name);
System.out.println("age=" + this.age);
System.out.println("address=" + this.address);
System.out.println("email=" + this.email);
}
}