-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNameGame.java
More file actions
60 lines (51 loc) · 1.66 KB
/
NameGame.java
File metadata and controls
60 lines (51 loc) · 1.66 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
/***
* Starter code for the NameGame
* 1 - add a field to store the location of the initial vowel
* 2 - implement the constructor
* 3 - implement, in turn, the B, F and M line methods
* TEST FREQUENTLY as you develop
* USE BREAKPOINTS and the debugger to identify errors
* 4 - add enhancements and refinements, discuss
**/
public class NameGame {
private String name; // different for each instance
// TODO use a field to store the location of first vowel
// constructor
public NameGame(String s){
//TODO - initialize all fields
}
// TODO implement this method correctly
private String buildBLine() {
return "TODO - B line\n";
}
// TODO implement this method correctly
private String buildFLine() {
return "TODO - F line\n";
}
// TODO implement this method correctly
private String buildMLine() {
return "TODO - M line\n";
}
// returns the complete verse
// implementation provided -- use as is
public String getLyrics() {
String start = "Let's do "+name+":\n"; // first line
String b = buildBLine();
String f = buildFLine();
String m = buildMLine();
String end = name + "!";
return start + b + f + m + end;
}
// returns the position of the first vowel or -1 if no vowels present.
// implementation provided -- use as is
public int findFirstVowel() {
String lower = name.toLowerCase();
for (int i = 0; i<lower.length(); i++) {
String s = lower.substring(i, i+1);
if (s.equals("a") || s.equals("e") || s.equals("i") || s.equals("o") || s.equals("u")) {
return i;
}
}
return -1;
}
}