-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRESimple.java
More file actions
36 lines (36 loc) · 1.26 KB
/
RESimple.java
File metadata and controls
36 lines (36 loc) · 1.26 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
import java.util.regex.*;
import java.util.Scanner;
/**
* Simple example of using regex class.
*/
public class RESimple {
public String processInput(String theInput){
Scanner stdIn = new Scanner(System.in);
boolean found;
String fromUser=null;
if (theInput.equals("Welcome to the Register, Please Enter Your Student Number")) {
do{
fromUser = stdIn.nextLine();
String pattern = "[0-9]+";
found = fromUser.matches(pattern);
if(found == false){
System.out.println("Please enter numbers\n");
}
}while(found==false);
}
else if (theInput.equals("We have received your Student Number, Now enter your name")) {
do{
fromUser = stdIn.nextLine();
String pattern = "[A-Za-z ]+";
found = fromUser.matches(pattern);
if(found == false){
System.out.println("Please enter alphabets\n");
}
}while(found==false);
}
else if (theInput.equalsIgnoreCase("We have received your Student Name, Press y to continue n to end")) {
fromUser = stdIn.nextLine();
}
return fromUser;
}
}