-
Notifications
You must be signed in to change notification settings - Fork 503
Expand file tree
/
Copy pathScannerInput.java
More file actions
32 lines (26 loc) · 812 Bytes
/
ScannerInput.java
File metadata and controls
32 lines (26 loc) · 812 Bytes
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
package hotel.management.input;
import java.util.InputMismatchException;
import java.util.Scanner;
public class ScannerInput {
private static Scanner scanner = new Scanner(System.in);
//Used To Get Integer inputs from User
public static int getInt(){
int newInt = 0;
try{
newInt = scanner.nextInt();
}catch (InputMismatchException e){
scanner.nextLine();
}
return newInt;
}
//Used to get String inputs from User
public static String getString(){
return scanner.nextLine();
}
//Used to get character input from user
public static char getCharacter(){
String word = getString();
if(word.isBlank() || word.length() > 1) return '?';
return word.toUpperCase().charAt(0);
}
}