-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconsoleUI.java
More file actions
44 lines (37 loc) · 1.18 KB
/
consoleUI.java
File metadata and controls
44 lines (37 loc) · 1.18 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
package com.javabooks;
import java.util.List;
import java.util.Scanner;
import java.util.Config
public class ConsoleUI {
private final Scanner scanner = new Scanner(System.in);
public void printMenu(){
System.out.println("\n====== JavaBooks ======");
System.out.println("1. Add book");
System.out.println("2. List books");
System.out.println("3. Search");
System.out.println("4. Borrow");
System.out.println("5. Return");
System.out.println("6. Remove");
System.out.println("7. Sort");
System.out.println("8. Statistics");
System.out.println("9. Save");
System.out.println("10. Load");
System.out.println("0. Exit");
System.out.print("Choose: ");
}
public int askInt(String msg){
System.out.print(msg);
return Integer.parseInt(scanner.nextLine());
}
public String ask(String msg){
System.out.print(msg);
return scanner.nextLine();
}
public void printBooks(List<Book> books){
if (books.isEmpty()){
System.out.println("No books.");
return;
}
books.forEach(System.out::println);
}
}