/****************************************************************************** * This program prints the lyrics to Farmer in the Dell * using a map to store the data. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ import java.util.HashMap; import java.util.Map; import org.pureprogrammer.Utils; public class FarmerInTheDell1 { static final Map PEOPLE = Utils.map(new Object[][] { {"farmer", "wife"}, {"wife", "child"}, {"child", "nurse"}, {"nurse", "cow"}, {"cow", "dog"}, {"dog", "cat"}, {"cat", "mouse"}, {"mouse", "cheese"} }); public static void main(String[] args) { String person = "farmer"; System.out.println("The famer in the dell"); System.out.println("The famer in the dell"); System.out.println("Hi-ho, the derry-o..."); System.out.println("The famer in the dell"); System.out.println(); while (!person.equals("cheese") ) { final String OTHER_PERSON = PEOPLE.get(person); System.out.println(Utils.join("", "The ", person, " takes the ", OTHER_PERSON)); System.out.println(Utils.join("", "The ", person, " takes the ", OTHER_PERSON)); System.out.println("Hi-ho, the derry-o..."); System.out.println(Utils.join("", "The ", person, " takes the ", OTHER_PERSON)); System.out.println(); person = OTHER_PERSON; } System.out.println("The cheese stands alone"); System.out.println("The cheese stands alone"); System.out.println("Hi-ho, the derry-o..."); System.out.println("The cheese stands alone"); } }