Skip to content

Instantly share code, notes, and snippets.

@spaghettiSyntax
Created January 5, 2018 05:37
Show Gist options
  • Save spaghettiSyntax/35d736ba7a393b0ba8fc14a800f31694 to your computer and use it in GitHub Desktop.
Save spaghettiSyntax/35d736ba7a393b0ba8fc14a800f31694 to your computer and use it in GitHub Desktop.
java/SwallowedAFlySong
// Assignment: Write a program that prints the lyrics to:
// "There Was an Old Lady Who Swallowed a Fly."
// This is Programming Project 3 of Chapter 1 of Building Java Programs.
public class SwallowedAFlySong {
public static void main( String[] args) {
// Animal verses that the Old Lady swallowed.
flyVerse();
spiderVerse();
birdVerse();
catVerse();
dogVerse();
goatVerse();
cowVerse();
horseVerse();
}
// Prints the Fly verse.
public static void flyVerse() {
System.out.println("There was an old lady who swallowed a fly.");
perhapsDie();
}
// Prints the Spider verse.
public static void spiderVerse() {
System.out.println("There was an old lady who swallowed a spider,");
System.out.println("That wiggled and wiggled and tickled inside her.");
System.out.println("She swallowed the spider to catch the fly.");
perhapsDie();
}
// Prints the Bird verse.
public static void birdVerse() {
System.out.println("There was an old lady who swallowed a bird;");
System.out.println("How absurd, to swallow a bird!");
birdCatchSpiderCatchFly();
perhapsDie();
}
// Prints the Cat verse.
public static void catVerse() {
System.out.println("There was an old lady who swallowed a cat.");
System.out.println("Imagine that, she swallowed a cat.");
System.out.println("She swallowed the cat to catch the bird ...");
birdCatchSpiderCatchFly();
perhapsDie();
}
// Prints the Dog verse.
public static void dogVerse() {
System.out.println("There was an old lady who swallowed a dog.");
System.out.println("What a hog! To swallow a dog!");
dogCatchCatCatchBird();
birdCatchSpiderCatchFly();
perhapsDie();
}
// Prints the Goat verse.
public static void goatVerse() {
System.out.println("There was an old lady who swallowed a goat.");
System.out.println("Just opened her throat and swallowed a goat!");
System.out.println("She swallowed the goat to catch the dog ...");
dogCatchCatCatchBird();
birdCatchSpiderCatchFly();
perhapsDie();
}
// Prints the cow verse.
public static void cowVerse() {
System.out.println("There was an old lady who swallowed a cow.");
System.out.println("I don't know how she swallowed a cow!");
cowCatchGoatCatchDog();
dogCatchCatCatchBird();
birdCatchSpiderCatchFly();
perhapsDie();
}
// Prints the Horse verse.
public static void horseVerse() {
System.out.println("There was an old lady who swallowed a horse -");
System.out.println("She's dead, of course.");
}
// Cow catch Goat catch Dog
public static void cowCatchGoatCatchDog() {
System.out.println("She swallowed the cow to catch the goat ...");
System.out.println("She swallowed the goat to catch the dog ...");
}
// Dog catch Cat catch Bird
public static void dogCatchCatCatchBird() {
System.out.println("She swallowed the dog to catch the cat ...");
System.out.println("She swallowed the cat to catch the bird ...");
}
// Bird catch spider catch fly end of verses.
public static void birdCatchSpiderCatchFly() {
System.out.println("She swallowed the bird to catch the spider");
System.out.println("That wiggled and wiggled and tickled inside her.");
System.out.println("She swallowed the spider to catch the fly.");
}
// Perhaps she'll die verse ending.
public static void perhapsDie() {
System.out.println("I dunno why she swallowed that fly,");
System.out.println("Perhaps she'll die.\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment