You are viewing our Forum Archives. To view or take place in current topics click here.
Very basic Java Methods(Sub Programs) - Need Help.
Posted:

Very basic Java Methods(Sub Programs) - Need Help.Posted:

BPM
  • Winter 2021
Status: Offline
Joined: Sep 12, 201014Year Member
Posts: 7,232
Reputation Power: 1137
Status: Offline
Joined: Sep 12, 201014Year Member
Posts: 7,232
Reputation Power: 1137
Currently learning the fundamentals and I am very stupid when it comes to coding. Could someone help me do this question. I have been at it for a while and I just don't understand how to go about it. I don't want the answer but I wont refuse it . I just need a push in the correct step

Thanks.

Question 1
Remember this nursery rhyme

Old McDonald had a farm, E-I-E-I-O
And on the farm he had a dog, E-I-E-I-O
With a woof woof here and a woof woof there
Here a woof, there a woof, everywhere a woof woof
Old McDonald had a farm, E-I-E-I-O

Suppose we wanted a program to print several verses of this song. We note that each verse
has the same structure and the only thing that changes is the name of the animal and the
sound the animal makes.

Write an action method that accepts two string parameters representing the animal and the
sound and which prints the verse to the console (use System.out.println) substituting the
animal and sound into the appropriate parts of the verse. Print a blank line at the end of
each verse (to separate successive verses). Now write a main method that prints several
verses using different animals and sounds by making appropriate calls the method above.
#2. Posted:
speed
  • Retired Staff
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
So you're going to need to need 2 inputs (system.in) in main

You'll pass those two variables to a function that accepts 2 parameters (animal & sound)

That function will print out the verses using the parameters.

And on that farm he had a {animal}...
with a {sound} {sound} here...

Etc.

Then you can just call that function from main for the last part.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.