Question: Write an application that receives and reads from a text file. Must be in java. Text file should be formatted as: BEGIN Square 2.0 Circle
Write an application that receives and reads from a text file. Must be in java. Text file should be formatted as:
BEGIN Square 2.0 Circle 1.5 Rectangle 3.0 4.0 Triangle 5.0 3.0 END
You can check file reading from our textbook or online. For example: https://www.javacodex.com/Files/Read-File-Word-By-Word
Once the application sees BEGIN, it should read the lines till it sees END. The purpose is to get the first word, determine which object to create, use the provided parameters to create the object, calculate its area (assume centimeters) and display the information in the console. So if we provide the text file shown above, then the output by calling each objects toString() method should be:
The area of the square is 4.00 cm2 The area of the circle is 7.06 cm2 The area of the rectangle is 12.00 cm2 The area of the triangle is 7.50 cm2
The area formula for the objects: Square = side x side Circle = x r2 Rectangle = side1 x side2 Triangle = height x base / 2
You should create a Shape class as the parent of all and define common behavior. Children should override toString() method and implement their unique ways of calculating the area. Parent Shape class should be abstract and define area as an abstract method. There should be two constructors for each object: default constructor, which sets everything to 0 and a fully defined constructor which assigns fields as you pass the information as parameters. Use the file I provided for testing purposes.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
