Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objective: Write a Java Eclipse compatible program that reads the lyrics to the

ID: 3762990 • Letter: O

Question

Objective:

Write a Java Eclipse compatible program that reads the lyrics to the song “Danger Zone” by Kenny Loggins (listed below) and replaces the word, “danger” with something else. The system should ask the user for a word to replace “danger”. The program should replace every instance ignoring capitalization, plurals, punctuations, etc. Also at the end the program should print out the new song to a new file.

First download the lyrics and place them in your project’s directory

The system should blindly replace any instance of photograph including plurals, capitalizations, or punctuations.

Danger counts

danger counts

dangers counts

danger! Counts

And so on

The word to replace “danger” can simply replace the word without any additional modifications. In other words, don’t worry about the pluralizing or adding punctuation to the new word.

Make sure to print the new lyrics to a new file.

It doesn’t have to match the formatting of the original.

Write your own main method!

Hints and Tips:

I would not advise anyone use the string method .replace unless they know how to use regular expressions confidently.

The scanner method .useDelimiter can be used to separate each of the words delimited by white space (“ “), while also ignoring end line’s (“ ”) and carriage returns (“ ”)

Lyrics:

Revvin' up your engine

Listen to her howlin' roar

Metal under tension

Beggin' you to touch and go

Highway to the Danger Zone

Ride into the Danger Zone

Headin' into twilight

Spreadin' out her wings tonight

She got you jumpin' off the deck

And shovin' into overdrive

Highway to the Danger Zone

I'll take you right into the Danger Zone

You'll never say hello to you

Until you get it on the red line overload

You'll never know what you can do

Until you get it up as high as you can go

Out along the edges

Always where I burn to be

The further on the edge

The hotter the intensity

Highway to the Danger Zone

Gonna take it right into the Danger Zone

Highway to the Danger Zone

Ride into the Danger Zone

Highway to the Danger Zone

Gonna take it right into the Danger Zone

Highway to the Danger Zone

Ride into the Danger Zone

Highway to the Danger Zone

Gonna take it right into the Danger Zone

Highway to the Danger Zone

Ride into the Danger Zone

Example Dialog:

Enter a word to replace DANGER with

taco

Finished writing to newSong.txt

Example File Print out:

Revvin' up your engine

Listen to her howlin' roar

Metal under tension

Beggin' you to touch and go

Highway to the taco Zone

Ride into the taco Zone

Headin' into twilight

Spreadin' out her wings tonight

She got you jumpin' off the deck

And shovin' into overdrive

Highway to the taco Zone

I'll take you right into the taco Zone

You'll never say hello to you

Until you get it on the red line overload

You'll never know what you can do

Until you get it up as high as you can go

Out along the edges

Always where I burn to be

The further on the edge

The hotter the intensity

Highway to the taco Zone

Gonna take it right into the taco Zone

Highway to the taco Zone

Ride into the taco Zone

Highway to the taco Zone

Gonna take it right into the taco Zone

Highway to the taco Zone

Ride into the taco Zone

Highway to the taco Zone

Gonna take it right into the taco Zone

Highway to the taco Zone

Ride into the taco Zone

Explanation / Answer

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

public class songtext {

    public static void main(String[] args) {

        try {

            FileReader reader = new FileReader("songfile.txt");

FileWriter writer = new FileWriter("newsongs.txt", true);

BufferedReader bufferedReader = new BufferedReader(reader);

String repl,repl1;

System.out.println(“Enter Word to replace”);

repl1=br.readLine();

System.out.println(“Enter by which Word you want to replace”);

repl=br.readLine();

int c=0;

  

           

String line;

while ((line = bufferedReader.readLine()) != null) {

int k=repl.length()-1;

int p=line.length()

            

while(c<p)

{

String s1=line.substring(n,k);

If (s1.equalsingoreCase(repl1)

{

writer.write(repl)

c=c+k;

}

else

{

char ch=s1.charAt(c);

writer.write(c);

c++;

}

            }

            reader.close();

writer.close();

        } catch (IOException e) {

            System.out.println(“Error in FILE IO operations”);

        }

    }

}