600.107 Introduction to Programming in Java
Homework #6 -- Due 11:30pm on Wednesday 10/25

Overview

The purposes of this assignment are to gain more practice with loops, as well as to learn how to work with external files and random data. You will also be exploring how to define your own (static) methods in Java when breaking a problem into smaller subroutines.

Deliverables: You must submit one zip file named with your java source code file (Hw6a.java) in it, named HW6-jhedLogin.zip, substituting your actual JHED login as the second part of the zipfile name. You are not required to include any text files (the output generated) in the zip, but may do so if you want. There is no starter file for this assignment.


Heat Plate Generation

For this assignment you will write a program that can generate a file with a text representation of a heat plate. Each plate will be a rectangular shape, represented as a two dimensional table. Each cell of the table can have one of three values: 'H' meaning heat is being applied to it, 'C' meaning that cooling is being applied there, and '.' meaning that it is unrestricted.

The overall operation of your program will be to get the height (# of rows) and width (# of columns) from the user representing the size of the plate to be generated. You will then create an output file whose name is based on the size of the plate. For example, the filename "hp20x30.txt" would be used when 20 is the height and 30 is the width of the plate. The first line in this file must be the dimensions of the plate (height then width). Each subsequent line will be the state of each cell on that row. The state of each cell must be randomly determined using these probabilites: there is a 65% probability of being unrestricted ('.'), with probability 25% it should be cooled ('C'), and 10% probability it will be hot ('H'). [Note: Your resulting file doesn't have to have exactly the corresponding ratio of 'H', 'C' and '.' values because they are, afterall, randomly determined.]

Here are the contents of a sample output file to show you the format; this file would be named "hp5x10.txt":

    5 10
    CCCCCC.C.C
    .........C
    ..HH..C..C
    ..HH.....C
    ..H......C
  

You are expected to create at least one static helper method (in addition to main) in order to break the problem into reasonably sized pieces. For example, you could have a method that randomly determines (based on the above distribution) what value one cell should have, and returns that value to main. You can call this method repeatedly from main to get all the values for the grid. Whatever you decide, you should definitely keep all input and output in main. Name your program Hw6a.java and remember to make it checkstyle compliant!


General assignment requirements, style and submission details: