Question

In: Computer Science

❐Part 1: SingASong Print “Old MacDonald Had a Farm” Lyrics using a function. To the function,...

❐Part 1: SingASong Print “Old MacDonald Had a Farm” Lyrics using a function. To the function, you pass the name of animal and the sound as parameters. Document your code carefully. Your program output must be identical to the sample output. OUTPUT OF SAMPLE RUN FOR PART 1 Old MacDonald had a farm Ee i ee i o And on his farm he had some cows Ee i ee i oh With a moo-moo here And a moo-moo there Here a moo, there a moo Everywhere a moo-moo Old MacDonald had a farm Ee i ee i o Old MacDonald had a farm Ee i ee i o And on his farm he had some chicks Ee i ee i o With a cluck-cluck here And a cluck-cluck there Here a cluck, there a cluck Everywhere a cluck-cluck Old MacDonald had a farm Ee i ee i o Old MacDonald had a farm Ee i ee i o And on his farm he had some pigs Ee i ee i o With an oink-oink here And an oink-oink there Here an oink, there an oink Everywhere an oink-oink Old MacDonald had a farm Ee i ee I o

Solutions

Expert Solution

ANSWER :-

GIVEN THAT :-

public class SingASong {

/*Function that takes name of the animal and sound as parameters and prints lyrics*/
public static void singSong(String name,String sound){

String article; /*used to store the article for this section of the song(a or an)*/

if(sound.equals("oink")){ /*checks if the sound passed is "oink" */

article="an"; /*article is set to "an"*/

}
else{

article="a"; /*article is set to "a"*/

}

/*The following lines print lyrics of the song line by line*/
System.out.println("Old MacDonald had a farm");

System.out.println("Ee i ee i o");

System.out.println("And on his farm he had some "+name+"s"); /*The name of the animal is used here*/


System.out.println("Ee i ee i "+(name.equals("cow")?"oh":"o")); /*Prints "Ee i ee i oh" if the animal is cow, else prints "Ee i ee i o"*/

System.out.println("With "+article+" "+sound+"-"+sound+" here"); /*The sound passed and article is used here*/

System.out.println("And "+article+" "+sound+"-"+sound+" there"); /*The sound passed and article is used here*/

System.out.println("Here "+article+" "+sound+", there "+article+" "+sound); /*The sound passed and article is used here*/

System.out.println("Everywhere "+article+" "+sound+"-"+sound); /*The sound passed and article is used here*/

System.out.println("Old MacDonald had a farm");

System.out.println("Ee i ee i o");


}

public static void main(String[] args){

singSong("cow","moo"); /*calls singSong method by passing cow as animal and moo as sound ,thereby printing the first part of the song*/

singSong("chick","cluck"); /*calls singSong method by passing chick as animal and cluck as sound ,thereby printing the second part of the song*/

singSong("pig","oink"); /*calls singSong method by passing pig as animal and oink as sound ,thereby printing the third part of the song*/
  

}
}

OUTPUT :-


Related Solutions

Sarah had a farm in Margaret River where part of the land was used for growing...
Sarah had a farm in Margaret River where part of the land was used for growing grapes. Her business involved growing the grapes and selling the crop to a local winery that was run by Jane. Two years ago, Sarah and Jane decided to go into business together and register a company Sarah Jane Pty Ltd, with the intention that Sarah would look after the growing of the grapes and Jane would extract the wine and promote the sale of...
Sarah had a farm in Margaret River where part of the land was used for growing...
Sarah had a farm in Margaret River where part of the land was used for growing grapes. Her business involved growing the grapes and selling the crop to a local winery that was run by Jane. Two years ago, Sarah and Jane decided to go into business together and register a company Sarah Jane Pty Ltd, with the intention that Sarah would look after the growing of the grapes and Jane would extract the wine and promote the sale of...
Sarah had a farm in Margaret River where part of the land was used for growing...
Sarah had a farm in Margaret River where part of the land was used for growing grapes. Her business involved growing the grapes and selling the crop to a local winery that was run by Jane. Two years ago, Sarah and Jane decided to go into business together and register a company Sarah Jane Pty Ltd, with the intention that Sarah would look after the growing of the grapes and Jane would extract the wine and promote the sale of...
Using an array and a function, print the values of an array backwards. Please follow these...
Using an array and a function, print the values of an array backwards. Please follow these guidelines: - Setup your array manually (whichever values you want, as many as you want and whichever datatype you prefer). - Call your function. You should send two parameters to such function: the array’s length and the array. - Inside the function, go ahead and print the array backwards. - Your function shouldn’t return anything.
MUST BE DONE IN C (NOT C++) Using an array and a function, print the values...
MUST BE DONE IN C (NOT C++) Using an array and a function, print the values of an array backwards. Please follow these guidelines: - Setup your array manually (whichever values you want, as many as you want and whichever datatype you prefer). - Call your function. You should send two parameters to such function: the array’s length and the array. - Inside the function, go ahead and print the array backwards. - Your function shouldn’t return anything
using the lyrics database schema in mysql provided below. 1.)List the artist name of the artists...
using the lyrics database schema in mysql provided below. 1.)List the artist name of the artists who do not have a webaddress and their leadsource is “Directmail”? 2.)List the names of members in the artist called 'Today'. 3.)Report the total runtime in minutes FOR EACH album in the Titles table. 4.)List the firstname, lastname of members who are represented by the salesperson “Lisa Williams” 5.)List EACH salesperson’s firstname along with the number of Members that EACH SalesPerson represents. below is...
Create the following SQL queries using the lyrics database below 1. List the first name, last...
Create the following SQL queries using the lyrics database below 1. List the first name, last name, and region of members who do not have an email. 2. List the first name, last name, and region of members who do not have an email and they either have a homephone ending with a 2 or a 3. 3. List the number of track titles that begin with the letter 's' and the average length of these tracks in seconds 4....
PLEASE PROVIDE A SPREADSHEET FOR EACH PART FOR PERSONAL REFERENCE Part 1: Using Excel’s Randbetween(0,9) function,...
PLEASE PROVIDE A SPREADSHEET FOR EACH PART FOR PERSONAL REFERENCE Part 1: Using Excel’s Randbetween(0,9) function, generate 200 samples of five random numbers between 0 and 9, calculate the mean of each sample. Show me the list of the 200 means. Typically, they should look like: 4.8, 3.6, 4.4, 6.0, etc. Part 2: Using Excel, calculate the overall mean of the 200 sample means (the average of the averages). This should be around 4.5. Part 3:   Using Excel, calculate the...
Part 1: Getting started and calling a function from a function. In this part, you will...
Part 1: Getting started and calling a function from a function. In this part, you will work with functions and functions that call functions. All code will be in main.cpp. Testing and grading will be via zyLab. Start with the template in zyBook. Write the following function: FindMax4(double num1, double num1, double num3, double num4) that returns the max of the arguments. Implement FindMax4() such that the body of the function comprises only a return statement that invokes FindMax() multiple...
Implement a non-recursive reverse print of linked list using stack and the main function to test:...
Implement a non-recursive reverse print of linked list using stack and the main function to test: You will need to finish the printReversed_nonrecursive method in ch04.LinkedStack2 class, and the ch04.UseStack2 is the main function to test. public class LinkedStack2<T> extends LinkedStack<T> { private void revPrint(LLNode<T> listRef) { if (listRef != null) { revPrint(listRef.getLink()); System.out.println(" " + listRef.getInfo()); } } public void printReversed() { revPrint(top); } /* use stack to implement non-recursive reverse print */ public void printReversed_nonrecursive() { } public...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT