forked from rick2785/JavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConversionContext.java
More file actions
70 lines (39 loc) · 1.81 KB
/
ConversionContext.java
File metadata and controls
70 lines (39 loc) · 1.81 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
public class ConversionContext {
private String conversionQues = "";
private String conversionResponse = "";
private String fromConversion = "";
private String toConversion = "";
private double quantity;
String[] partsOfQues;
public ConversionContext(String input)
{
this.conversionQues = input;
partsOfQues = getInput().split(" ");
fromConversion = getCapitalized(partsOfQues[1]);
toConversion = getLowercase(partsOfQues[3]);
quantity = Double.valueOf(partsOfQues[0]);
conversionResponse = partsOfQues[0] + " "+ partsOfQues[1] + " equals ";
}
public String getInput() { return conversionQues; }
public String getFromConversion() { return fromConversion; }
public String getToConversion() { return toConversion; }
public String getResponse() { return conversionResponse; }
public double getQuantity() { return quantity; }
// Make String lowercase
public String getLowercase(String wordToLowercase){
return wordToLowercase.toLowerCase();
}
// Capitalizes the first letter of a word
public String getCapitalized(String wordToCapitalize){
// Make characters lower case
wordToCapitalize = wordToCapitalize.toLowerCase();
// Make the first character uppercase
wordToCapitalize = Character.toUpperCase(wordToCapitalize.charAt(0)) + wordToCapitalize.substring(1);
// Put s on the end if not there
int lengthOfWord = wordToCapitalize.length();
if((wordToCapitalize.charAt(lengthOfWord -1)) != 's'){
wordToCapitalize = new StringBuffer(wordToCapitalize).insert(lengthOfWord, "s").toString();
}
return wordToCapitalize;
}
}