I am tired and lost, sitting here on a Friday night trying to finish my program. The program prompts the user to enter a series of animal names and sounds, and print the corresponding verses from the song "Old MacDonald had a farm". The program will continue printing verses until the user enters "no more" instead of an animal name and sound. This is what I have so far:
Code:
import java.util.*;
/**
* Program that outputs lyrics to Old Macdonald, by asking the user to enter a type of animal
* and it's noise or no more to end the program
*/
public class OldMacDonald
{
public static void main (String[] args)
{
Scanner stdin = new Scanner(System.in);
System.out.println("Let's sing \"Old MacDonald had a farm\": ");
System.out.println("Please enter an animal and a noise, or no more to stop playing.");
String animal = stdin.nextLine();
while (!animal.equals("no more"))
{
break;
}
String noise = stdin.next();
String stop = stdin.next();
printFirstLast();
printMiddleVerse(animal, noise);
printFirstLast();
}
public static void printFirstLast()
{
System.out.println("Old MacDonald had a farm, E-I-E-I-O.");
}
public static void printMiddleVerse(String animal, String noise)
{
System.out.println("And on that farm he had some " + animal + ", E-I-E-I-O ");
System.out.println("With a " + noise + "-" + noise + " here, and a " + noise + "-" + noise + " there");
System.out.println("Here a " + noise + ", there a " + noise);
System.out.println("Everywhere a " + noise + "-" + noise);
}
}
Comment