600.108 Intro Programming Lab Week 5 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< >> This is your last week to work with your original partner. << >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< PROBLEM STATEMENT ------------------------------------------------------------ This week you will be writing two related programs that work with files. Program A is to create random data which is written to a plain text file that will serve as input for Program B. Program B will read data from a plain text file that contains shape names, sizes, and display characters, and for each one, display it on the screen using Unicode graphics. Program B must process three different types of shapes: a rectangle, a triangle, and a diamond. For each shape, the input must specify a character which will be used to draw the shape, and size information. The size of a rectangle is specified by two numbers (height & width), whereas a triangle and diamond require only one number (same for height and width). Furthermore, a diamond can only be an odd number size. The only user (keyboard) input to Program B is the name of the file containing the list of shapes to display. ^ # ***** ^^ ### ***** ^^^ ##### ***** ^^^^ ### # Program A must use the Random class to generate a plain text file called "shapeData.txt" that can be used as input for Program B. First this program should randomly generate a number between 5 and 15 which indicates how many shapes to include in the file. Then for each shape you must have on one line of the text file: its type (rectangle, triangle, diamond - all equally likely), a character with which to display it chosen from this set: {*+-=%^#@}, and its size. For the triangle the size can be any integer between 1-10 inclusive. For the diamond the size can be any odd integer between 3-19 inclusive. For the rectangle there must be two integer sizes, each between 2 and 40 inclusive, corresponding to the height and the width. Here is a brief example of input corresponding to the shapes above: rectangle * 3 5 triangle ^ 4 diamond # 5 Phase I: We'll write Program A first. In this phase, write a program to create a plain text output file called "shapeData.txt", generate the number of shapes (between 5 and 15) and then for each one generate and write its type on a line of the output file. Make sure you save (close) the output file at the end of your program! Phase II: Finish Program A so that in addition to the shape type, it also generates the display character and appropriate size values for each type, and writes them all on the same line in the text file. (over) Phase III: Now start Program B. First write a program that will read the name of an input file from the user, then read every line in the file and display just the type of each shape. Next add to Program B so that each piece of data is read from each line of the input file - the shape type, display character and size(s). Phase IV: Now start to implement the actual shape displays. We have created a starter program (shapestart.java) for you with a few method declarations to help organize this part of the processing. Call the methods from main, and then fill in the method bodies one at a time. Start with the rectangle since that will be the easiest. Next do the triangle which should be a variation of the rectangle. Phase V: Lastly write the code to create the diamond. There are no shortcuts to center data when you print. You will have to explicitly output all necessary spaces so that it looks correct. Can you think of a method to add to your program that will make this easier?