Download the folder download/lab5/ShapesProject_lab_starter from your cs account. Take a look at all the classes included. In this task, you will continue working on the ShapesDriver.java class you started working on in class.
Once we start working with files, many of our objects need certain methods that are particularly well-suited to this interaction between our objects and the files (for example, we saw in class the method serialize() which gave us a very concise representation of our Shape objects). In this task, you will work on adding constructors to our classes that take in as input String representations of objects.
First, take a look at the Circle class. Note the existence of a second constructor. Now add a second constructor that works in a similar fashion for the Rectangle class, and one for the Triangle class.
Many of our upcoming tasks will deal with reading from a File. It might be easier to deal with arrays of Strings instead of File objects, so, thinking ahead, we'll define a helper method which will read our Files into String[], where each element of the array is a line from the file.
Please catch the relevant FileNotFoundException right here, in this method. Remember that in general it is a good idea to deal with any exception your code may produce as close to its source as possible!
Don't forget to close the scanner when you are done with reading the text file.
Test this method so that you have some assurance that the file was read correctly into the array.
Write a method called collectTrianglesFromFile() that reads in from a file (formatted like shapeData.txt) and returns all the triangles found in the file.
First, write down a detailed list of all the steps you'll have to tackle for this problem. Write this list as in-line comments for the method. This will be the starting point for your code.
Are there any methods already defined that can help you? What should be the return type for this method?
Make sure to test this method on the file provided.
Write a method called collectLargeShapes() that reads in from a file (formatted like shapeData.txt) and returns all the shapes whose perimeter is larger than some threshold value.
Once again, write down a detailed list of all the steps you'll have to tackle for this problem. Write this list as in-line comments for the method. This will be the starting point for your code.
Don't forget to test this method!
Some times input data may not be formed as expected, and this may have consequences in the way the program runs. Consider your ShapeDriver program: