BIT 115– Assignment #4 (A4 Basic) Due No Revision Wednesday, August 24

advertisement
BIT 115– Assignment #4 (A4 Basic)
Due: Wednesday, August 24 No Revision
A4: Basic vs. Advanced
For this assignment, you will choose between doing this assignment as 'Basic' A4 or 'Advanced' A4.
While you're welcome to do both of them, only one will be handed in (and thus graded). You're free to
try them both, decide which one you like, and then hand that one in.
Part 1: Tracing
You will find the provided Trace.java file on the Homework web page. You must trace through this
program, and hand in your trace in a file named Part_1_Trace_Table_Starter. While we haven't traced
through everything that the program contains (most notably, we haven't traced through for loops, nor
through arrays, in-class), you should be able to do a reasonable job of tracing the program nonetheless.
Because you haven't been shown specific formats for everything that you'll need to trace, you should
focus on choosing a clear, understandable format for tracing things. In order to help guide your work,
there is a program trace table provided to you that demonstrates one way of formatting things.
Specifically, it shows a way of representing the robot in one column, of representing the array in one
column, and of tracing through a for loop accurately and clearly.
For the array, note that it is represented as something like [ 2, 0, 3], where the value 2 is stored in slot
#0 of the array, the second element (element #1) has the value 0, and the third-and-last element
(element #2) has the value 3.
Part 2: Writing a Program: Histograms!
A histogram is a type of bar chart that's used to display a collection of numbers. While most of the
histograms are drawn vertically, we're going to draw a histogram horizontally. For this assignment, you
will first get a robot to draw a (horizontal) histogram of Things, and then print out a (horizontal)
histogram using standard Java I/O.
For this part, you will need to use the DrawHistogram.java file that is provided to you on the website.
1|Page
Let's say that the histogramData array contains the numbers [3, 5, 1, 0, 4, 2, 1]. You need to add code
to main so that the robot would produce a "histogram" like the following:
Notice that the first element in the histogramData array ( element histogramData[0] ) has the value 3,
and that the first (top-most) horizontal bar is 3 Things wide. The second value in the array is 5, and the
second row contains 5 Things, and so on.
2|Page
Note that in order to get full credit, you must implement (and use the DrawRow) method on the robot,
which will put down all the Things for 1 row, and then return the original starting location.
After you've done that, then you need to implement the printHistogram method in the
HistogramPrinter helper class. Its one parameter will be a reference to the histogramData array. You
will then print out (using normal Java I/O) a (horizontal) histogram. For example, an array containing the
same values as above ( [3, 5, 1, 0, 4, 2, 1] ) would generate the following output:
***
*****
*
****
**
*
Note that the provided starter file demonstrates the difference between System.out.println("*"); and
System.out.print("*");, which you should remove before handing in your homework.
3|Page
Hint: If you haven't yet covered arrays-as-parameters in class yet, just copy the code for
creating & initializing the histogramData array into the printHistogram method, and make sure
that everything else works ok. You will get lose points if you don't replace that code with an
array parameter, but this will at least allow you to work on this part of the assignment
independently of the arrays-as-parameters topic.
Multi-File Program
For this assignment, you are required to split your overall program into (at least) two files.
You should keep the main function in the provided DrawHistogram.java file, and you must move at least
one of the other two classes into a separate file.
You are not required to move both of the classes each into their own separate files, but it would be
good practice.
If you do not turn in at least two (2) separate files you will lose points!
Make sure that you hand in ALL the files that you've created/modified!
Group Work, Commenting
You are allowed to work with ONE other person on this assignment (i.e., pairs of people)
You should comment your code, paying particular attention to areas that are difficult to understand. If
you found something to be tricky when you wrote it, make sure to comment it so that the next person
(the instructor, who's grading you) understands what your code is doing. It is not necessary to comment
every single line.
The purpose of requirement is to both help you understand, and have you demonstrate, a thorough
understanding of exactly how your program works.
4|Page
Every file that you turn in should have:
At the top of each file that you normally edit, you should put your name (first and last) or names if you
are in a team, the name of this class (“BIT 115”), and quarter and year (“Fall 2012”), and the assignment
number (“A4”). If you’re handing this in again for a re-grade, make sure to increase version number by
one (from “A4” to “A4.1").
You normally edit the Java source code files (.Java files), and any Word/.PDF documents that you're
handing in (if any).
In general, you should make sure to do the following before handing in your project:
All variables used should have meaningful names.
The code should be formatted consistently, and in an easy to read format.
What to turn in:
A single .ZIP file, which folder should contain:



Part_1_Trace_Table_Starter.doc (trace file)
DrawHistogram.java (main file)
HistogramRobot.java (or some other name for at least one method file)
5|Page
Download