In this problem, you are asked to write a program to define shapes of objects in space and store them in an array. For this, you have to define class Shape that you will extend into three sub-types: Circle, Square, Triangle. Class Equilateral Triangle extends Triangle. All shapes share the following members: color, x-coordinate, y-coordinate. They also share a common variable dimensions that is set to 2 for this instance of the problem since we are dealing with a two dimensional space. The last two instance fields specify the location of the center of the object in a two-dimensional plane. A circle has a radius, a square has a side length. A triangle object has an array of size three to the length of the sides of the triangle. An equilateral triangle is a triangle that has all three sides equal in length. Also, each of these shapes has a method called area() and one called perimeter() that compute respectively the area and the perimeter of each object depending on the shape. In addition to this, they all have a method toString() that outputs the values in all the fields of an object. It is possible to move triangles and squares but not circles. As you are proceeding with the design of the code, declare class Shape as abstract since you should not be able to instantiate it.
The program starts by displaying the following menu:
– – – – – – – –
Enter your choice:
If the user enters 1, the following menu is displayed:
– — – – – – – – — – – – – –
If the user enters A, the program prompts for the radius and x and y coordinates and adds a circle to the array.
If the user enters B, the program prompts for the side length, x and y coordinates and adds a square to the array.
If the user enters C, the program prompts for the three sides, x and y coordinates and adds a triangle or equilateral triangle in case the three sides have equal length.
If the user enters D, the program returns to the previous menu.
The menu is displayed after each input except ‘D’. Any incorrect input should display an error message.
If the user enters 2, the program prompts for the x and y coordinates and deletes all shapes at the specified coordinates.
If the user enters 3, the program prompts for the x and y coordinates and compute and displays the area and perimeter of the shapes at these coordinates.
If the user enters 4, the program displays all shapes in the array.
If the user enters 5, the program prompts for the distance by which the object is to move and whether the object should be moved vertically or horizontally, up or down if vertically, left or right if horizontally. It updates the x and y coordinates accordingly. All shapes should remain within a square that is 200 units wide and 200 units high. They cannot cross the border.
If the user enters 6, the program reads shapes from a text file. The file should have the following format:
circle, 0, 1
square, 2, 3
circle, 4, 2
triangle, 5, -3
equilateral triangle, -1, -3
If a line does not contain valid information, it should be skipped and a proper message should be displayed on the screen. The program should proceed to the next line.
If the user inputs 7, the program exits. Before terminating, the contents of the array are saved to a text file called output.txt.
The menu is displayed again after each correct input. Any incorrect input should output an error message and display the menu again.
You cannot do well on the exams unless you do the assignment yourself!
Plagiarism and cheating policy
Cheating is a serious offense. If a student is found to have copied part or all of the assignment, he or she will receive a zero on the assignment. During exams, if a student is caught cheating, he or she will receive a zero on the exam. This might result in the student getting an F on the course. NO EXCUSES WILL BE ACCEPTED. The same applies to the person providing others with material. The same applies to plagiarism (presenting someone else’s work as being one’s own work).
Deadlines for submitting assignments will be announced in class or on the assignments. They are firm. Students must respect them. A student failing to meet the deadline will get 5% of the grade deducted per day late. A student cannot replace an assignment with another one. If he or she fails to submit an assignment, a zero will be scored on the missed assignment. To illustrate, if the student submits assignments 1 and 3 only, he or she will get a 0 on Assignment 2, Assignment 1 or 3 cannot compensate for the missed assignment.