Project - Lab
Project - Lab
Design a small project using arrays and object-oriented techniques using Java. The project will be
used to represent the geometric shapes that can do the following tasks.
1- Create a class called “point” which includes two variables x and y and has the following methods:
-
a. A constructor to initialize x and y by 0.
b. A constructor to initialize x and y by two input parameters.
c. Setx to change the value of x.
d. Sety to change the value of y.
e. Print point, the output should be like this (1,3).
f. DistanceToPoint to measure the distance between this point and another point.
2- Create a class called “Triangle” that includes 3 points in an array. It should have the following
methods:
a. A constructor to initialize the triangle points.
b. SetPoints to change the three points of the triangle.
c. GetPoints to get the array that includes the points.
d. PrintPoints print the three points as (0,0) -> (1,4) -> (3,2)
e. GetArea to compute and return the triangle area.
f. GetPerimeter to compute and return the perimeter of the triangle.
3- Create a class called “Rectangle” that includes 4 points in an array. It should have the following
methods:
a. A constructor to initialize the Rectangle points.
b. SetPoints to change the four points of the triangle.
c. GetPoints to get the array that includes the points.
d. PrintPoints print the three points as (0,0) -> (1,0) -> (1,1) -> (0,1)
e. GetArea to compute and return the area.
f. GetPerimeter to compute and return the perimeter.
4- Create another class called pentagonal shape to represent a shape with five sides and choose by
yourself five different functions.
5- Create a set of static variables and methods to count the number of created objects from each
shape.
6- Use suitable modifiers for variables and methods based on what we studied in the course.
7- Create a new class that includes a main method to create some objects from each class and test
the methods and classes.
8- Try to handle all types of errors that may occur from the user.
9- You should use comments to explain every function.
10- Your program should be friendly and easy to use.
11- Draw the UML diagrams for the created classes using any online tool and attach them to the
project folder as images.