CSc 221 Fall 2005 Both Sections: HW6 Consolidated Requirements

I didn't intend this homework as a case study in how to deal with clients who can't make up their minds, and I apologize for the confusion--but you might be surprised how much like the real world this is sometimes.

Here's what you do.

  1. For the five musicians whose biographies appear in the code for the first version, write a program that puts them into a HashMap.
  2. Print abbreviated musician names in the Console window and ask the user to enter the name of a musician and press enter.
  3. Write code, which can be in the same class, to produce HTML for a page about this musician. His (they are all men) name should appear as an H1 heading. The paragraphs of the of the bio can be separated using one statement with a split method. Surround each paragraph with the HTML paragraph tags, <p> and </p>. The default action will place a blank line between paragraphs for readability.
  4. Use the code snippet at the end to write the HTML to a file on your hard drive. (When I run your program I'll change the file name in your code, of course.)
  5. Write code to send that same information about the musician to the Console window, with a blank line between paragraphs. The blank line is a matter of sending the newline character \n (in quotes, of course) in an output string. Can be done in a separate println statement, or appended to the paragraph string.

That's all that is required. For extra learning and practice but no extra credit, make the selection of the musician's name and the presentation of the bio information a nice GUI. I'll show a sample in class, written by a 473 student.

 

Here is code to show how to specify a file. You will want to make the musician's name the value of a variable; don't send everybody to Bach. The code shown will write all the paragraphs of the Bach bio to the file shown, with HTML tags.

 

try {
   FileWriter rawOut = new FileWriter( "Bach.html" );
   PrintWriter out = new PrintWriter( rawOut );
   for ( String s : paragraphs ) {
      out.println("<p>");
      out.println(s);
      out.println("</p>");
   }
   out.close();
}
catch ( IOException error ) {
   System.err.println( "Error writing to output file: " +    error );
}

 

Finally, here is a sample giving the minimum structure of an HTML file:

<html>
<head>
<title>HW 6 Model Solution</title>
</head>
<body>
<h1>Johann Sebastian Bach</h1>
<p>
JS Bach was born.
</p>
<p>
He wrote great music.
</p>
<p>
He had lots of children.
</p>
<p>
He died.
</p>
</body>
</html>

 

 Back to Dan McCracken's  Home Page