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

Write a program that reads the lyrics to the song “Danger Zone” by Kenny Loggins

ID: 3763203 • Letter: W

Question

Write a program that reads the lyrics to the song “Danger Zone” by Kenny Loggins 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 (“ ”).

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

Complete Program:

// File: DangerZone.java
import java.io.*;
import java.util.*;
public class DangerZone
{
public static void main(String[] args) throws FileNotFoundException
{
  Scanner keyboard = new Scanner(System.in);
  String inputfile = "song.txt";
  String outputfile = "newSong.txt";
    
  System.out.println("Enter a word to replace DANGER with");
  String word = keyboard.next();  
  
  Scanner infile = new Scanner(new File(inputfile));
  PrintWriter outfile = new PrintWriter(new File(outputfile));
  
  Scanner scan = infile.useDelimiter("Danger");
  
  System.out.println("Finished writing to " + outputfile);
  
  while(scan.hasNext())
  {
   outfile.print(scan.next());
   
   if(scan.hasNext())
    outfile.print(word);
  }  
  
  infile.close();
  outfile.close();
}
}

Input file: song.txt

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

Output file: newSong.txt

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote