BIT 115– Assignment #4 (A4)

DUE DATE: < Listed on the course schedule >

Arrays, Loops, and Parameters

A4: Basic vs. Advanced

 

For this assignment, you will choose between doing this assignment (the 'Basic' A4) or doing the 'Advanced' version of A4.  While you're welcome to do both of them, only one will be handed in (and thus graded).  You're free to try 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.

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.  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.  You're welcome to put everything else in main.

After you've done that, then you need to implement the printHistogram method in the HistogramPrinter helper class.  It's 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.

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.

    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.

 

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), the name of this class (“BIT 142”), and the year and quarter, and the assignment number, including the revision number, which starts at 0 (“A2.0”).  If you’re handing this in again for a regrade, make sure to increase the minor version number by one (from “A2.0”, to “A2.1").
You normally edit the Java source code files (.Java files), and any Word/.PDF documents that you're handing in (if any).
You do not normally edit the .SLN or .CSPROJ files, and so you should not try to put this identifying information in those files.

 

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:

  1. Part_1_Trace_Table_Starter.doc

  2. DrawHistogram.java

 

How to electronically submit your homework:

 

This was covered in class.