-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringHelper.java
79 lines (78 loc) · 1.75 KB
/
StringHelper.java
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
/*
* Created by Noah Shaw
*/
public class StringHelper {
//Methods
public static String meshStrings(String firstString, String secondString)
{
System.out.println("Meshing "+firstString+" with "+ secondString+".");
int counter = 0;
if(firstString.length() < secondString.length())
{
counter = secondString.length();
}
else if(secondString.length() < firstString.length())
{
counter = firstString.length();
}
else
{
counter = secondString.length();
}
String newString = "";
char firstC = '\0';
char secondC = '\0';
for(int i = 0; i < counter; i++)
{
if(i < firstString.length())
{
firstC = firstString.charAt(i);
newString = newString + firstC;
}
if(i < secondString.length())
{
secondC = secondString.charAt(i);
newString = newString + secondC;
}
}
return newString;
}
public static String replaceVowelsWithOodle(String aString)
{
System.out.println("Replacing vowels with oodle in the word "+aString+".");
String newString = "";
for(int i = 0; i < aString.length(); i++)
{
char c = aString.charAt(i);
c = Character.toLowerCase(c);
if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
{
newString += "oodle";
}
else
{
newString += c;
}
}
return newString;
}
public static double weight(String aString)
{
System.out.println("The weight of the word "+aString+" is:");
double weight = 0;
for(int i = 0; i < aString.length(); i++)
{
char c = aString.charAt(i);
c = Character.toLowerCase(c);
if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
{
weight = weight + 2.5;
}
else
{
weight = weight + 3.4;
}
}
return weight;
}
}