im new to java and i really need ur help guys!
question is:
Using a series of methods, output the popular song "My Bonnie Lies Over the Ocean". However, instead of using "Bonnie", allow the users to enter a name of their choice.
Lyrics:
My Bonnie lies over the ocean
My Bonnie lies over the sea
My Bonnie lies over the ocean
Oh bring back my Bonnie to me
Bring back, bring back
Bring back my Bonnie to me, to me
Bring back, bring back
Bring back my Bonnie to me
Last night as I lay on my pillow
Last night as I lay on my bed
Last night as I lay on my pillow
I dreamed that my Bonnie was dead
Bring back, bring back
Bring back my Bonnie to me, to me
Bring back, bring back
Bring back my Bonnie to me
Oh blow ye the winds o'er the ocean
And blow ye the winds o'er the sea
Oh blow ye the winds o'er the ocean
And bring back my Bonnie to me
Bring back, bring back
Bring back my Bonnie to me, to me
Bring back, bring back
Bring back my Bonnie to me
The winds have blown over the ocean
The winds have blown over the sea
The winds have blown over the ocean
And brought back my Bonnie to me
Bring back, bring back
Bring back my Bonnie to me, to me
Bring back, bring back
Bring back my Bonnie to me
this is what i have so far:
/ The "Lyrics" class.
public class Lyrics
{
public static void main (String[] args)
{
string name;
System.out.println ("enter the name of the user");
name = ReadLib.readString ();
System.out.println ("my" + name + "bonnie lies over the ocean");
} // end of main method
public static double (
} // end of Lyrics class
this is all i have im not sure about the whole;
so can you guys plz help?! plzzzzzz~~~~
need help wit this "method" problemusing series of method to rewrite the song
Page 1 of 1
6 Replies - 588 Views - Last Post: 16 April 2008 - 04:36 PM
Replies To: need help wit this "method" problem
#2
Re: need help wit this "method" problem
Posted 16 April 2008 - 06:56 AM
System.out.println ("my" + name + "bonnie lies over the ocean"); should be System.out.println ("my" + name + " lives over the ocean");
After that you don't have to think much.
After that you don't have to think much.
#3
Re: need help wit this "method" problem
Posted 16 April 2008 - 01:40 PM
but how do u use method to do solve the question? plz help
can u jus do one verse for me
can u jus do one verse for me
#4
Re: need help wit this "method" problem
Posted 16 April 2008 - 02:20 PM
spit-king, on 16 Apr, 2008 - 01:40 PM, said:
but how do u use method to do solve the question? plz help
can u jus do one verse for me
can u jus do one verse for me
1licca explained it to you.
I guess you didn't worked very hard on the problem
OK one solution would be....
import java.util.Scanner;
/** A class which hold the Lyric in an array of String */
public class Lyrics
{
String[] song = {
"My Bonnie lies over the ocean",
"My Bonnie lies over the sea",
"My Bonnie lies over the ocean",
"Oh bring back my Bonnie to me",
"Bring back, bring back",
"Bring back my Bonnie to me, to me",
"Bring back, bring back"
};
// method that returns the song
String[] getSong() {
return song;
}
// static method to do the job
public static void main (String[] args)
{
// pickup by what replacing "Bonnie"
String name;
Scanner scan = new Scanner(System.in);
System.out.print ("Enter the name of the user: ");
name = scan.next();
// Get an instance of Lyrics
Lyrics lyrics = new Lyrics();
// Get the song lines
String[] str = lyrics.getSong();
// lopp thru all lines
for(int i = 0; i < str.length; i++) {
// replacing "Bonnie" by the name I have scanned
System.out.println(str[i].replaceAll("Bonnie", name));
}
} // end of main method
} // end of Lyrics class
That way, if you decide to put your song in a text file only the getSong() method will have to be changed. It will have to open the file and put every line in a String array.
#5
Re: need help wit this "method" problem
Posted 16 April 2008 - 03:03 PM
thank you so much for the answer!!!
just one more question
can you put the whole lyrics in here?:
String[] song = {
"My Bonnie lies over the ocean",
"My Bonnie lies over the sea",
"My Bonnie lies over the ocean",
"Oh bring back my Bonnie to me",
"Bring back, bring back",
"Bring back my Bonnie to me, to me",
"Bring back, bring back"
};
and my school doesnt use scanner so what do i do with this:
Scanner scan = new Scanner(System.in);
just one more question
can you put the whole lyrics in here?:
String[] song = {
"My Bonnie lies over the ocean",
"My Bonnie lies over the sea",
"My Bonnie lies over the ocean",
"Oh bring back my Bonnie to me",
"Bring back, bring back",
"Bring back my Bonnie to me, to me",
"Bring back, bring back"
};
and my school doesnt use scanner so what do i do with this:
Scanner scan = new Scanner(System.in);
#6
Re: need help wit this "method" problem
Posted 16 April 2008 - 03:28 PM
spit-king, on 16 Apr, 2008 - 03:03 PM, said:
can you put the whole lyrics in here?:
I guess that if you cut & paste the code from this topic you can also cut&paste the lyric
you will just have to add the " before every line
and add a " after every line plus a "," but for the last one
spit-king, on 16 Apr, 2008 - 03:03 PM, said:
and my school doesnt use scanner so what do i do with this:
Scanner scan = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
The Scanner object is part of Java, it is used to scan input... in your case the console
so don't worry we won't use your school scanner... would be hard to insert it into your PC
just make sure to put the line
import java.util.Scanner;
at the beginning of your code as in the code I wrote for you
Before you used
name = ReadLib.readString ();
but I do not have your ReadLib library so I used a standard Java one which is Scanner
#7
Re: need help wit this "method" problem
Posted 16 April 2008 - 04:36 PM
thank you so much for your help man!!!
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|