Sie sind auf Seite 1von 3

This problem set should be programmed using Java and done individually.

Design the classes first before starting


the program. Use UML for the class diagrams. Once you have a good design, encode the classes. Write also a
class called ShapeTest, which includes the main method.

1. Create a class Point. Objects of a point have an x and y coordinate. A point can be moved given a new x
and y coordinate. The default coordinate of a point is the origin (0,0).

2. Create a class Shape. Shapes are composed of different points*. Each shape also has a color (String)
and a shape ID (int). The following operations can be done on a shape:
TranslateX
- The shape will be moved +/- units along the X-axis
TranslateY
- The shape will be moved +/- units along the Y-axis
Scale
- The shape will increase/decrease in size by a given factor.
ex. scale by 2 means shape will increase its size by 2.
scale by 0.5 means shape will decrease its size by half.
scale by 1 means it will not change its size.
Rotate
- The shape will rotate by a certain number of degrees in clockwise or
counter-clockwise direction.
ex. rotate by +45 means shape will rotate 45deg clockwise.
rotate by -270 means shape will rotate 90deg counter-clockwise

computeArea
- This method returns the area of the shape.

Add necessary getter methods for a shape. Add a counter to be able to keep track of the number of shapes
created.

*The number of points depends on the kind of shape.

3. Create a class Triangle. A Triangle has 3 points and a counter that keeps track of the number of
triangles created.

4. Create a class Quadrilateral. A Quadrilateral has 4 points and a counter that keeps track of the
number of quadrilaterals created.

5. Create a class Circle. A circle only stores one point (the center). From the center, it will be able to
construct itself using its radius.

Add a counter to be able to keep track of the number of circles created.

6. Create a class ShapeTest. This class contains the main method that allows the user to do the following:
a. Create a Shape
Allows the user to create either a triangle, square, or circle.
Once a shape is selected, it asks the user for the necessary data:
for a triangle: 3 points
for a quadrilateral: 4 points
for a circle: center + radius
Each shape is assigned a shape ID for reference. The shape ID is unique and is assigned
incrementally.
b. Delete a Shape
This allows the user to delete a specific shape (by entering the shape ID or all the shapes.
Deletion of shapes does not affect the next shape ID to be assigned to a newly created shape.

c. Scale all Shapes


The user enters a scale factor and changes all the shapes.

d. Translate all shapes along the X-axis


The user enters the amount of units the shapes will move along the x-axis

e. Translate all shapes along the y-axis


The user enters the amount of units the shapes will move along the y-axis

f. Compute area of all Shapes


Choosing this feature will instruct the program to display the area of all shapes that were
created. The shapes will be displayed according to the order they were created. Output
format will be:
<Shape ID><TAB><Shape><Tab><area upto 2 decimal places>
ex. 1 CIRCLE 4.23
2 TRIANGLE 0.23
5 TRIANGLE 11.49

g. Check how many shapes there are


This feature will display the total number of Circles, Triangles, Quadrilaterals and total
shapes.

ex. Number of Circles: 3


Number of Triangles: 10
Number of Quadrilateral: 2

Total Shapes: 15
h. Display Shape Details
This feature displays the details of one shape or all shapes. If only one shape’s details will
be displayed, the user has to enter the shape ID.
The details of a shape should be displayed using the following format:
<Shape ID><TAB><Shape><TAB><List of point coordinates>
If the shape is a circle, follow the following format:
<Shape ID><TAB>CIRCLE<TAB> <Center coordinate><SPACE><radius>

Enter shapeID (0 for all shapes): 0

1 CIRCLE (0,0) 3
2 TRIANGLE (1,1) (1,0) (0,1)
5 QUADRILATERAL (5,3) (7,1) (6,-4) (-2,0)
BONUS:
i. Rotate all Shapes
The user enters the number of degrees the shapes will be rotating. Note that a Circle does
not need to rotate.
Deadline: Oct. 18 (MW classes) and Oct. 19 (TH classes) first 5 minutes of the class.

Deliverables:

1. Documentation (printout) of the project will be placed in a properly-labeled (project name: MiniMP1_PointShape, full name
and section, term and AY) brown envelope. Documentation includes:
a. UML Class Diagram
b. Source codes
c. List of all files and corresponding directories in the CD (table with two columns: filename and directory

2. Source code (printout) must have internal documentations as well. You may use javadoc comments or usual comments for your
classes and methods. Describe each class and its method and their parameters. Follow prescribed software development standards. In
BlueJ, create a project with the name: MiniMP1_PointShape_<lastname>_<firstname>. Make sure you fill up the information
in README.TXT. Organize your files in packages as needed.

3. Burn your source codes (*.java), compiled classes (*.class), executable file (*.jar), javadoc (if there’s any; *.html), documentation
(*.doc), and other necessary files (graphics, output files, etc) on a properly-labeled (project name: MiniMP1_PointShape, full
name and section, term and AY) CD with case and place it in the same brown envelope.

Das könnte Ihnen auch gefallen