Question: Would you please help in doing this homework. Objective In this assignment, you will practice solving a problem using object-oriented programming techniques in Java; specifically,

Would you please help in doing this homework.

Objective

In this assignment, you will practice solving a problem using object-oriented programming techniques in Java; specifically, you will use the concept of object composition. Basically, you

are asked to implement a Java application with several classes.

Problem Description

Implement three classes to keep track of a collection of triangles. You will also write a fourth class to test the implementation.

The classes are described below.

Point Class

The Point class represents a point on a plane. Every object of type Point has the following

attributes.

x, an integer that stores the x-coordinate of a point on a plane

y, an integer that stores the y-coordinate of the same point on a plane

id, an integer that uniquely identifies the Point object.

A static field (say, idCounter) to generate the value to be stored in id. Increment this field once within the constructor and store the value in id. Since there is exactly one instance of idCounter, every Point object will have a unique value stored in id.

The class also has the following constructor and methods:

A constructor that takes the x and y coordinates as parameters in that order and stores the two values in the respective fields. It also generates a unique id and stores the value in the id field.

Getters for x and y.

An override of toString(), which returns a properly-formatted String object, showing the values of id, x, and y coordinates, in an understandable way.

An override of equals () and hashCode(). Two Point objects are equal only if they have the same id. All standard constraints on equals () must be satisfied

Triangle Class

Every Triangle object has

an array of Point objects of length 3. The cells store the three Point objects, representing the triangle vertices.

id, an integer that uniquely identifies the Triangle object.

A static field (say, idCounter) to generate the value for id. Increment this field once

within the constructor and store the value in id.

Besides these fields, the class has the following constructors and methods.

A constructor that takes three Point objects as parameters and stores them in the three

cells of the field of the Point array. It also generates a unique id and stores the value in

the id field.

A constructor with no parameters and uses the first constructor to store null values in

each of three cells and generate and store a unique id.

A constructor with a single Point object as parameter and uses the first constructor to

store this Point in the first cell (index 0) and null values in the other two cells and

generate and store a unique id.

A method named setPoint() with two parameters:

a) index an integer that specifies the vertex to be changed.

b) point a Point object to be stored in the cell corresponding to index.

The method stores the point in the appropriate cell (0 1, 2) given in index. If index

is anything other than 0, 1, or 2, the method does not store the Point object.

An override of toString(), which returns a properly-formatted String object,

showing the values of id, and the Point objects in an understandable way. Use

toString() of Point appropriately.

An override of equals() and hashCode(). Two Triangle objects are equal only

if they have the same id. All standard constraints on equals() must be satisfied.

Triangles Class

This is a collection class that uses java.util.LinkedList to store Triangle objects.

The class has the following members.

A field named triangles a linked list of Triangle objects. Use generics properly.

A method named addTriangle() with a single parameter of type Triangle. The

return type is void. The method adds the Triangle object to the triangles list.

A method named deleteTriangle() with a single parameter of type Triangle. The

return type is Triangle. The method deletes the Triangle object from the

triangles list and returns the deleted Triangle. If the Triangle object is not in

the list of Triangle objects, the method returns null.

A method named getTriangle() with a single parameter of type int. The return type

is Triangle. The method returns the Triangle object with an id equal to the one

given in the parameter. If such a Triangle object is not in the list of Triangle objects,

the method returns null.

An override of toString(), which returns a properly-formatted String object,

showing the values of all Triangle objects in an understandable way. Use

toString() of Triangle appropriately.

Driver class

Your driver class should do the following actions:

Create nine Point objects with your choice of x and y coordinates, but every

coordinate value should be unique

Create three Triangle objects. Each Point object should be stored in exactly one

Triangle object.

Invoke every constructor and method of Triangles, Triangle, and Point, at

least once, including toString() and equals(). The toString() methods

of Point and Triangle could be indirectly invoked, via the toString()

method of Triangles. Do not worry about testing hashCode().

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!