2.2 Step 1: Make a File ReaderFor this step, you will only need to modify, and thusfocus on, the following class:• ReadShapeFile.javaFigure 1: Empty Window with a Title: Shape Booooi-iinggg FrameYou will also need to look at only the constructors ofthe following classes:• Circle.java• Oval.javaPretend the rest of the code does not exist. This is howwe break large programs into smaller components thata human can understand and work with. It’s also howthe rest of engineering works as well. Think about howthe parts of a car engine are compartmentalised nicelyinto components. You don’t need to hold the entirefunctionality of the engine in your head at one time– just the component you are working on and how itinterfaces with the rest of the system.It is very important that you only modify code in thefiles you are asked to modify. If your developmentenvironment suggests to change code outside thesefiles don’t do it – even if it makes things magicallycompile and the red text disappears. Please assume themistake is in the code you have just written and not inthe code supplied. It is important you do not modifycode supplied (except where indicated) because thiscould cause Autograder to fail to properly read yoursubmission.In the first step of the assignment, you’ll create a file reader that reads the shape files supplied to you. Eachline of the shape file specifies a shape. The format ofthis line differs depending on the shape to be created.Fortunately, the first entry of the line always indicateswhat shape is to be created from this input. For exam-ple, to create a circle:circle To create an Oval, the line in the file would be as fol-lows:oval All these entries are on a single line of the file. I havebroken them into two lines for readability. Angularbrackets are placeholders for numbers/values as fol-lows:• - time in millisecondssince the start of the program after which theshape is inserted• - The starting position of the shapein the plane• - The velocity of the shape as a vec-tor• - True if the shape is filled and falseotherwise• - The colour of the shapeFor circle only, you have:• - the diameter of the circleFor oval only, you have:• - the width and height(major and minor axis) of the oval.You cannot modify the file format in this assignment.These files will be automatically on autograder and ifyou modify file format your program marking will fail.In ReadShapeFile.java, write methods to readfiles consisting of circles and ovals only. Also, youcan assume that the file is sorted by insertion time.This means that the lines of the file must be in increas-ing order. I would start by trying to read a single line of the filefollowed by multiple lines, printing them to the screento ensure you are reading the data correctly. Then, cre-ate instances of the shape objects and print them out.You can do this by calling the toString() methodthat has already been given to you.If the file does not exist, quit the program grace-fully and output Could not find to the screen (standard out) with re-placed by the file that will not open. However, youcan assume that each line of the file has the cor-rect syntax. To test your code, please try to run theTwoRedCircles.txt file. Start by printing outeach line your read to the terminal to make sure youare reading the data correctly. Then, create instancesof the objects and use the toString() method toprint out the object and make sure that it is being cre-ated correctly.Extracted text: import javafx.scene.paint.Color; import java.io.*; import java.util.Scanner; public class ReadShapeFile { // TODO: YoU will likely need to write four methods here. One method to // construct each shape // given the Scanner passed as a parameter. I would suggest static // methods in this case. /** Reads the data file used by the program and returns the constructed queue ...*) private static Queue readLineByLine(Scanner in) { Queue shapeQueue = new Queve(); //read in the shape files and place them on the Queue //Right now, returning an empty Queue. You need to change this. return shapeQueue; }
Extracted text: import javafx.scene.paint.Color; import java.io.*; import java.util.Scanner; public class ReadShapeFile { // TODO: YoU will likely need to write four methods here. One method to // construct each shape // given the Scanner passed as a parameter. I would suggest static // methods in this case. /** Reads the data file used by the program and returns the constructed queue ...*) private static Queue readLineByLine(Scanner in) { Queue shapeQueue = new Queve(); //read in the shape files and place them on the Queue //Right now, returning an empty Queue. You need to change this. return shapeQueue; }
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here