-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.java
More file actions
88 lines (83 loc) · 2.53 KB
/
Copy pathParser.java
File metadata and controls
88 lines (83 loc) · 2.53 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import java.util.Scanner;
public class Parser {
public static void main(String args[]){
String text = "";
Scanner sc=new Scanner(System.in);
System.out.println("Enter Text: ");
text=sc.nextLine();
String final_text = parse(text);
System.out.println(final_text);
}
public static String parse(String s){
String[] str=s.split(" ");
String res="";
boolean flag=false;
boolean caps=false;
int ctr=0;
for(int i=0;i<str.length;++i) {
if (flag == false) {
if (str[i].equals("Number") && i+1<str.length && getNumber(str[i+1])!=0){
ctr = getNumber(str[i+1]);
flag=true;
res+= "\n";
res += ctr+". ";
i++;
caps=true;
}else{
if(caps==true){
res+= firstLetterCaps(str[i])+" ";
caps=false;
}
else
res += str[i]+" ";
}
}
else{
if (str[i].equals("Number") && i+1<str.length && str[i+1].equalsIgnoreCase("next")){
ctr++;
res+= "\n";
res += ctr+". ";
i++;
caps=true;
}
else{
if(caps==true){
res+= firstLetterCaps(str[i])+" ";
caps=false;
}
else
res += str[i]+" ";
}
}
}
return res;
}
public static int getNumber(String num){
int n=0;
if(num.equalsIgnoreCase("one"))
n=1;
else if(num.equalsIgnoreCase("two"))
n=2;
else if(num.equalsIgnoreCase("three"))
n=3;
else if(num.equalsIgnoreCase("four"))
n=4;
else if(num.equalsIgnoreCase("five"))
n=5;
else if(num.equalsIgnoreCase("six"))
n=6;
else if(num.equalsIgnoreCase("seven"))
n=7;
else if(num.equalsIgnoreCase("eight"))
n=8;
else if(num.equalsIgnoreCase("nine"))
n=9;
return n;
}
public static String firstLetterCaps(String s){
String r="";
if(s.length()>0)
r += Character.toUpperCase(s.charAt(0))+s.substring(1,s.length());
return r;
}
}