-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStage3.java
62 lines (59 loc) · 1.86 KB
/
Stage3.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
import helper.Help;
import java.util.ArrayList;
import java.util.Scanner;
/**
* In this stage,
* you need to create a menu.
* The menu should display the following options:
* 1. Search information.
* 2. Print all data.
* 0. Exit.
* The user must select a menu item and
* then enter data if necessary.
* Your program must not stop until the
* corresponding option (the exit option) is chosen.
* Decompose the program into separate methods to make it easy to understand
* and to further develop or edit.
*/
public class Stage3 {
/**
* method to print the options.
* */
public static void print() {
System.out.println("=== Menu ===");
System.out.println("1. Find a person");
System.out.println("2. Print all people");
System.out.println("0. Exit");
}
/**
* main method working as per the options provided by user.
* */
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number of people:");
int noOfPerson = Integer.parseInt(scanner.nextLine());
ArrayList<String> listOfPerson = new ArrayList<>();
System.out.println("Enter all people:");
while (noOfPerson-- > 0) {
listOfPerson.add(scanner.nextLine());
}
boolean exit = false;
while (!exit) {
print();
int choice = Help.getChoice(scanner);
switch (choice) {
case 0 :
exit = Help.choice0();
break;
case 2 :
Help.choice2(listOfPerson);
break;
case 1 :
Help.choice1(scanner, listOfPerson);
break;
default:
System.out.println("Incorrect option! Try again.");
}
}
}
}