-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnts2.java
More file actions
59 lines (47 loc) · 1.42 KB
/
Copy pathAnts2.java
File metadata and controls
59 lines (47 loc) · 1.42 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
public class Ants2 {
/**
* Ants2.java
* Now the methods take parameters and return results
*
*/
public static void main(String[] args) {
System.out.println(verse(1));
System.out.println(chorus());
System.out.println(verse(2));
System.out.println(chorus());
} // end main
public static String chorus(){
String result = " \n";
result += "...and they all go marching \n";
result += "down \n";
result += "to the ground \n";
result += "to get out \n";
result += "of the rain \n";
result += "Boom boom boom boom boom boom boom boom \n";
result += " \n";
return result;
} // end chorus
public static String verse(int verseNum){
String result = "";
String distraction = "";
//determine the distraction
switch (verseNum){
case 1:
distraction = "suck his thumb";
break;
case 2:
distraction = "tie his shoe";
break;
default:
distraction = "I have no idea...";
} // end switch
//create the verse
result += "The ants go marching " + verseNum;
result += " by " + verseNum + " hurrah, hurrah... \n";
result += "The ants go marching " + verseNum;
result += " by " + verseNum + " hurrah, hurrah... \n";
result += "The little one stops to " + distraction + " \n";
result += " \n";
return result;
} // end verse
} // end class def