-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSong.java
126 lines (114 loc) · 4.01 KB
/
Song.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
123
124
125
126
// Evan Ma
// 4/4/2019
// CSE142
// TA: Dylan Hayre (i forgot his name tbh sorry mate, it's section AC)
// Assignment #1
//
// This program will attempt to print out the
// song “There Was an Old Woman Who Swallowed a Fly.”
public class Song{//summary of song described in main
public static void main(String[] args){
phraseFly();
stanza0();
phraseSpider();
stanza1();
phraseBird();
stanza2();w
phraseCat();
stanza3();
phraseDog();
stanza4();
phraseCustom();
stanza5();
phraseHorse();
}
// phrases used in the first line of each stanza starts here. total of 7, counting horse
// if faced with same hw again, compress method into phraseAnimal(string Animal, string Rhyme)
public static void phraseFly(){//see refrainFly() for notes
System.out.println("There was an old woman who swallowed a fly.");
}
public static void phraseSpider(){
System.out.println("There was an old woman who swallowed a spider,");
System.out.println("That wriggled and iggled and jiggled inside her.");
}
public static void phraseBird(){
System.out.println("There was an old woman who swallowed a bird,");
System.out.println("How absurd to swallow a bird.");
}
public static void phraseCat(){
System.out.println("There was an old woman who swallowed a cat,");
System.out.println("Imagine that to swallow a cat.");
}
public static void phraseDog(){
System.out.println("There was an old woman who swallowed a dog,");
System.out.println("What a hog to swallow a dog.");
}
public static void phraseCustom(){
System.out.println("There was an old woman who swallowed a hive,");
System.out.println("How is she alive to swallow a hive");
}
public static void phraseHorse(){
System.out.println("There was an old woman who swallowed a horse,");
System.out.println("She died of course.");
}
// collapsing each refrain in here, stanza_i represents the (i+1)-th stanza
// yeah i can see why we need for-loops now
public static void stanza0(){
refrainFly();
}
public static void stanza1(){
refrainSpider();
refrainFly();
}
public static void stanza2(){
refrainBird();
refrainSpider();
refrainFly();
}
public static void stanza3(){
refrainCat();
refrainBird();
refrainSpider();
refrainFly();
}
public static void stanza4(){
refrainDog();
refrainCat();
refrainBird();
refrainSpider();
refrainFly();
}
public static void stanza5(){
refrainCustom();
refrainDog();
refrainCat();
refrainBird();
refrainSpider();
refrainFly();
}
// refrain construction using println
// all this ctrl-c/ctrl-v could've went away if I
// could declare a refrain(string "predator", string "prey") method
// but nope, suffering ensures
public static void refrainCustom(){
System.out.println("She swallowed the hive to catch the dog,");
}
public static void refrainDog(){
System.out.println("She swallowed the dog to catch the cat,");
}
public static void refrainCat(){
System.out.println("She swallowed the cat to catch the bird,");
}
public static void refrainBird(){
System.out.println("She swallowed the bird to catch the spider,");
}
public static void refrainSpider(){
System.out.println("She swallowed the spider to catch the fly,");
}
public static void refrainFly(){ //refrainFly repeats after every stanza, gets special treatment
System.out.println("I don't know why she swallowed that fly,");
System.out.println("Perhaps she'll die.");
System.out.println(); // added to reduce "redundancy", since each stanza ends on
// "perhaps she'll die" anyways
}
}