-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathPig_v02.java
123 lines (89 loc) · 3.49 KB
/
Pig_v02.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//class Pig
//a Pig Latin translator
// v02 --
// change filename to Pig.java to compile
public class Pig {
private static final String VOWELS = "aeiou";
/*=====================================
boolean hasA(String,String) -- checks for a letter in a String
pre: w != null, letter.length() == 1
post: hasA(“cat”, “a”) → true
hasA(“cat”, “p”) → false
=====================================*/
public static boolean hasA( String w, String letter ) {
// *** your implementation here ***
return false; //placeholder to get past compiler
}
/*=====================================
boolean isAVowel(String) -- tells whether a letter is a vowel
precondition: letter.length() == 1
=====================================*/
public static boolean isAVowel( String letter ) {
// *** your implementation here ***
return false; //placeholder to get past compiler
}
/*=====================================
int countVowels(String) -- counts vowels in a String
pre: w != null
post: countVowels(“meatball”) → 3
=====================================*/
public static int countVowels( String w ) {
// *** your implementation here ***
return 42; //placeholder to get past compiler
}
/*=====================================
boolean hasAVowel(String) -- tells whether a String has a vowel
=====================================*/
public static boolean hasAVowel( String w ) {
// *** your implementation here ***
return false; //placeholder to get past compiler
}
/*=====================================
String allVowels(String) -- returns the vowels in a String
pre: w != null
post: allVowels(“meatball”) → “eaa”
=====================================*/
public static String allVowels( String w ) {
// *** your implementation here ***
return ""; //placeholder to get past compiler
}
/*=====================================
String firstVowel(String) -- returns first vowel in a String
pre: w != null
post: firstVowel("") --> ""
firstVowel("zzz") --> ""
firstVowel("meatball") --> "e"
=====================================*/
public static String firstVowel( String w ) {
// *** your implementation here ***
return ""; //placeholder to get past compiler
}
/*=====================================
boolean beginsWithVowel(String) -- tells whether a String begins with a vowel
pre: w != null and w.length() > 0
post: beginsWithVowel("apple") --> true
beginsWithVowel("strong") --> false
=====================================*/
public static boolean beginsWithVowel( String w ) {
// *** your implementation here ***
return false; //placeholder to get past compiler
}
/*=====================================
String engToPig(String) -- converts an English word to Pig Latin
pre: w.length() > 0
post: engToPig("apple") --> "appleway"
engToPig("strong") --> "ongstray"
engToPig("java") --> "avajay"
=====================================*/
public static String engToPig( String w ) {
// *** your implementation here ***
return ""; //placeholder to get past compiler
}
public static void main( String[] args ) {
String letter = "a";
for( String w : args ) {
System.out.println( w + " has " + letter + "? "
+ hasA( w, letter ) );
}
}
}//end class Pig