Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pleas use java language and also I included the Point class package plane; /****************************************************************** * A point representing a location (x, y) in coordinate space,

Pleas use java language and also I included the Point classimage text in transcribed

package plane;

/****************************************************************** *

A point representing a location (x, y) in coordinate space, * specified in integer precision. ******************************************************************/

public class Point {

/*********************************************** * data fields * stores the (x, y) location of point ***********************************************/ private int x; private int y; /***************************************************************** * constructs and initializes a point at the origin (0,0) * of the coordinate plane. *****************************************************************/ public Point() { this(0,0); // calls constructor Point(int, int) } /****************************************************************** * constructs and initializes the point to the location specified * by point p. * @param p reference to the specified point object. ******************************************************************/ public Point(Point p) { setLocation(p); // reduce redundancy with setLocation } /***************************************************************** * constructs and initializes the point to the specified (x,y) * location. * @param x the x coordinate of point to construct. * @param y the y coordinate of point to construct. *****************************************************************/ public Point(int x, int y) { setLocation(x, y); // reduce redundancy with setLocation } /******************************************************************** * returns the x coordinate of the point in integer precision. * @return x the x coordinate of point object. ********************************************************************/ public int getX() { return x; } /******************************************************************** * returns the y coordinate of the point in integer precision. * @return y the y coordinate of point object. ********************************************************************/ public int getY() { return y; } /********************************************************************** * moves the point to the specified location in the (x, y) coordinate * plane. This method is identical to setLocation(int, int). * @param x the specified x coordinate value. * @param y the specified y coordinate value. **********************************************************************/ public void move(int x, int y) { this.x = x; this.y = y; } /********************************************************************* * changes the location of the point in the coordinate plane to the * location specified by point p. * @param p the specified point . *********************************************************************/ public void setLocation(Point p) { x = p.x; y = p.y; } /********************************************************************* * changes the location of the point in the coordinate plane to the * location specified by the values (x, y). * @param x the specified x coordinate value. * @param y the specified y coordinate value. *********************************************************************/ public void setLocation(int x, int y) { this.x = x; this.y = y; } /******************************************************************** * returns string representation of point. * @return point (x, y) coordinates. ********************************************************************/ public String toString() { return "(" + x + ", " + y + ")"; } /******************************************************************** * translates the point at the location (x,y) by dx along the * x-axis and dy along the y-axis, resulting with the point at * location (x + dx, y + dy). * @param dx the specified x coordinate value. * @param dy the specified y coordinate value. ********************************************************************/ public void translate(int dx, int dy) { x += dx; // x = x + dx y += dy; // y = y + dy } }

B. Work on your own to create the following generic class Create a generic class called Generic that has data field: data of generic type T location for the Generic Object 1. 2. constructors: The overloaded constructors will construct and initialize a memory i. The first constructor is the default constructor. It calls the second constructor and passes a null value. The second sets the data field data to the value passed. ii. 3. mutator after the object is made then you can update the data field to the value passed with the method set. 4. accessors: after the object is made then you can retrieve the information in data with the method get and a string representation toString. 5. method: after the object is made you can retrieve the hash code of the object + 200000000. Note: This hash code overrides the hash code of the object class and returns an encrypted integer value of the object plus the constant indicated. The method signature for the hash code is as follows: public int hashCode () Create a client program called Genericclient that has the ability to make a Generic object of type Point, String and Double and write methods that will allow you to print out their contents as a string and hash code. a. Point (2, 6)- Use your Point class from Lab 1. b. String: I am a String that uses the Generic class. C. Double: 6.08

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions