Question
In the class ReadShapeFile, there is a file called shapes.txt. Ive opened it on line 2 This has a list of shapes. Youre going to
- In the class ReadShapeFile, there is a file called shapes.txt. Ive opened it on line 2 This has a list of shapes. Youre going to read each line for each shape and call createShape, which will create one of the available shapes, Circle, Rectangle, or Square and returns a GeometricObject, which you will add to the ArrayList called shapeList.
The file has some unavailable shapes. If the shape is unavailable, createShape should throw a ShapeException. You should catch a ShapeException and continue reading the file.
By the end, the side of shapeList should be 20.
Summary:
- Create a ShapeException class
- Implement createShape to return the appropriate shape depending on the string shapeName
- createShape should throw a ShapeException if it is not a Circle, Square, or Rectangle
- A loop should read in the shapes.txt file lineby-line
- If the file cannot be read, you should break out of the loop
- If you get a ShapeException, you should continue reading the file
import java.io.*; import java.util.ArrayList;
import shapes.*;
/* your tasks: * create a class called ShapeException * createShape should throw a ShapeException * in main(), you should catch the ShapeException * */ public class ReadShapeFile {
public static GeometricObject createShape(String shapeName) { /* if shapeName is "Circle" return Circle(); * if shapeName is "Square" return Square(); * if shapeName is "Rectangle" return Rectangle(); * if it is not any one of these, it should throw * a ShapeException */ return null; } public static void main(String[] args) { ArrayList
System.out.println(shapeList); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started