Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will need to define two classes: (1) a simple Point class that has instance

ID: 3632604 • Letter: Y

Question

You will need to define two classes: (1) a simple Point class that has instance variables (int) for the x and y coordinates of a two-dimensional point, and (2) a GraphDisplay class that extends JFrame and has the following code in it:

import java.awt.*;
import javax.swing.*;
One instance variable that is an array of Point items, defined as
private Point[] node = new Point[7]; // 7 points is enough to test the program
Create a window of size 400 x 400 pixels with the title "Graph Display" and a background color of LIGHT_GRAY. To do this, define a constructor for your GraphDisplay class that calls the constructor for JFrame via
super("Graph Display");
and then sets its size via
setSize(400, 400);
Enter the points of the graph as (x, y)
node 0 = (360, 40)
node 1 = (25, 25)
node 2 = (100, 150)
node 3 = (250, 100)
node 4 = (370, 370)
node 5 = (50, 350)
node 6 = (210, 210)
At each node[i], draw a GREEN circle of size (15, 15)
At each node[i], enter a text label of i. For example, at node[4], put the label "4".
Draw lines from node[0] to node[1], [1] to [2], [2] to [3], [3] to [4], [4] to [5], [5] to [6], and [5] to [3].

Explanation / Answer

namespace Graphics { /// /// Class Point models a /// point in a two-dimensional plane. /// public class Point { /// /// Instance variable x represents the Point's x-coordinate. /// private int x; /// /// Instance variable y represents the Point's y-coordinate. /// private int y; /// /// The Point's x-coordinate. /// public int X { get { return x; } set { x = value; } } /// /// The Point's y-coordinate. /// public int Y { get { return y; } set { y = value; } } /// /// This constructor initializes the new Point to (0,0). /// public Point(): this(0,0) {} /// /// This constructor initializes the new Point to /// (,). /// /// The new Point's x-coordinate. /// The new Point's y-coordinate. public Point(int xor, int yor) { x = xor; y = yor; } /// /// This method changes the point's location to the given /// coordinates. /// /// The new x-coordinate. /// The new y-coordinate. /// public void Move(int xor, int yor) { x = xor; y = yor; } /// /// This method changes the point's location by the given /// x- and y-offsets. /// /// /// The following code: /// /// Point p = new Point(3,5); /// p.Translate(-1,3); /// /// results in p's having the value (2,8). /// /// The relative x-offset. /// The relative y-offset. /// public void Translate(int xor, int yor) { x += xor; y += yor; } /// /// This method determines whether two Points have the same /// location. /// /// /// The object to be compared to the current object. /// /// /// True if the Points have the same location; otherwise, false. /// /// /// public override bool Equals(object o) { Point p = o as Point; if (p == null) return false; return x == p.x && y == p.y; } /// /// Computes the hash code for a Point. /// /// /// A hash code computed from the x and y coordinates. /// public override int GetHashCode() { return x ^ y; } /// /// Report a point's location as a string. /// /// /// A string representing a point's location, in the form (x,y), /// without any leading, training, or embedded whitespace. /// public override string ToString() { return "(" + x + "," + y + ")"; } /// /// This operator determines whether two Points have the same /// location. /// /// The first Point to be compared. /// The second Point to be compared. /// /// True if the Points have the same location; otherwise, false. /// /// /// public static bool operator ==(Point p1, Point p2) { if ((object)p1 == null || (object)p2 == null) return false; return p1.x == p2.x && p1.y == p2.y; } /// /// This operator determines whether two Points have the same /// location. /// /// The first Point to be compared. /// The second Point to be compared. /// /// True if the Points do not have the same location; /// otherwise, false. /// /// /// public static bool operator !=(Point p1, Point p2) { return !(p1 == p2); } /// /// /// This is the entry point of the Point class testing program. /// /// /// This program tests each method and operator, and is intended /// to be run after any non-trvial maintenance has been performed /// on the Point class. /// /// public static void Main() { // class test code goes here } } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote