600.108 Intro Programming Lab, Week 6, Fall 2017
Getting Started: Hopefully you will remember who your new partner is
from last week! Get together again this week, and start in opposite
driver/navigator roles. Do the posted quiz6 on Blackboard before
digging in.
This week you will be working with random data, and also creating
several subroutines from scratch to break the problem into smaller
pieces. (You'll also learn some html formatting as a side bonus.) Part
of your task will be to design a subroutine breakdown. Then you will
incrementally implement methods that we have specified for you in
order to put a solution together in a well-structured way.
PROBLEM STATEMENT ----------------------------------------------------
This week you will write a program that will convert a plain text file
to a randomly formatted html file. The random formats will consist of
centering (or not), font colors and heading styles. Most html
formatting instructions, called tags, follow a general pattern of
being enclosed in angle brackets to begin, as in , and using
a slash to end, as in . In "proper" html, when multiple
formats are applied to a line, their tags should be properly nested.
Centering a line is accomplished by putting the html tag
before the line starts, and following the line with to end
the centering format. Colors can be expressed as a six character
string preceded by a #. Every two characters in the string are the
same, the first pair representing the amount of Red, second for Green
and third is Blue (RGB values). Possible values for the characters
are the digits 0, 3, 6, 9 and the letters C and F. In order to set
the font of some text to a particular color in an html document, use
before the text and after the text.
Lastly, there are 6 levels of headings in html. Each one is
designated with a tag pair , where the # is a digit from 1
to 6.
Your program should prompt the user for the name of an input plain
text file and then create an output file whose name is the same as the
input file name, with ".html" added to the end. In this output file,
every line of the original file should be repeated, with a random
color and heading style formatting it, either centered or not. A
sample input file and matching output file are posted on the course
webpage. In order to view the html itself (what your program must
create), choose the view file/page source menu option of your web
browser after displaying the output file.
------------------------------------------------------------------
Step 1) DESIGN: Come up with a set of three methods that would help
organize the processing of this program, in addition to the main
method. Write a short description of each. You can do this as a
comment in the start of your program file, or as a plain text file.
Explain your method choices to a lab leader.
>>> Switch driver/nagivator roles <<<
Step 2) CODING: Write a (static) method that takes a string as a
parameter, chooses a random number between 1 and 6 and given this
number #, returns string. For example, if the parameter
value is "hello" and the number chosen is 4, the method returns
"hello
". For testing purposes, write a main method that
calls this method with 3 different strings and displays the results
on the screen. Add a javadoc comment for your method. Make sure
everything is checkstyle compliant. Have a lab leader review your
work.
>>> Switch driver/nagivator roles <<<
Step 3) CODING: Write a (static) method that has a string parameter,
and randomly decides whether to return the original string without
any changes, or to return "string" instead. Add
some code to main to test this out, and include a javadoc comment
for this method. Have a lab leader review your work.
>>> Switch driver/nagivator roles <<<
Step 4) CODING: Write a (static) method that takes a string parameter,
and chooses three characters from the set {0,3,6,9,C,F} randomly. It
then transforms string into "string"
where x, y, and z were the three randomly chosen characters,
returning the result. Add some code to main to test this method,
and a javadoc comment for the method. Have a lab leader review your
work.
>>> Switch driver/nagivator roles <<<
Step 5) Now we're ready to do the intended main processing. You can
put a block comment around the existing tests to comment them out.
Instead, write statements that prompt a user for a filename, then
reads the file, transforms each line in all the above-described
ways, and then writes it to another file. The output filename must
be "inputfilename"+".html", where inputfilename was the given input
file name. Have a lab leader review your work.
Extra) IF YOU FINISH SUPER EARLY: For extra practice rewrite your
solution to last week's lab using several methods - ideally one for
each menu operation.
Step 6) Zip all the files together from today's lab and email to both
students. Then each student must submit their work on Blackboard for
the week, noting their partner's name and JHED login in the
submission textbox. You must then delete your files off the lab
computer and logout before leaving! Failure to do so constitutes an
ethics violation.