Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I fix it? 1. Task: Create a Point class. The class should contain 2 fields (integers called x and y, for the x

image text in transcribedimage text in transcribed

image text in transcribedimage text in transcribedimage text in transcribed

image text in transcribedimage text in transcribedimage text in transcribed

How do I fix it?

1. Task: Create a Point class. The class should contain 2 fields (integers called x and y, for the x and y coordinates, positive values) and the following methods: . . . . Default and alternate constructors. Two getters (accessors) to return the x and y coordinates A method named set to set the coordinates to the parameters passed; invalid values set to 0 A method named print to print each Point object as (x, y) A method toString() A method named equals to compare 2 Point objects for equality 2 methods named copy and getCopy to make a copy of a Point object into another Point object A method named distance FromOrigin to calculate the distance between a point and the origin at(0, 0) A method named distance to calculate the distance from a point to a given point. method named translate to shift the location of a point by a given amount. A method named isHorizontal that returns true if any given point lines up horizontally with a given point. A method named isVertical that returns true if any given Point object lines up vertically with a given Point object. A method named slope that returns the slope of the line between this point object and a given Point object. . . . 2. Task: Create a client for the point class. Be very thorough with your testing (including invalid input) and have output similar to the sample output below: ---After declaration, constructors invoked--- Using toString(): First point is (0, 0) Second point is (7, 13) Third point is (7, 15) Second point (7, 13) lines up vertically with third point (7, 15) Second point (7, 13) doesn't line up horizontally with third point (7, 15) Enter the x-coordinate for first point: retgre Not an integer! Try again! Enter the x-coordinate for first point: 89.67 Not an integer! Try again! Enter the x-coordinate for first point: -13 ERROR! Should be positive. Enter the x-coordinate for first point: 15 Enter the y-coordinate for first point: fwgfe Not an integer! Try again! Enter the y-coordinate for first point: 90.6 Not an integer! Try again! Enter the y-coordinate for first point: -32 ERROR! Should be positive. Enter the y-coordinate for first point: b Not an integer! Try again! Enter the y-coordinate for first point: 23 First point (after call to set) is (15, 23) Distance from origin for first point 27.46 Distance from origin for second point 14.76 Distance between first point and second point 12.81 First point (after call to translate (5, 10)) is (20, 33) Second point (after call to translate (15, 5)) is (22, 18) ---Call to equals: The 2 points are NOT equal. ---Calls to copy and print--- First point (after call to copy) is (20, 33) Second point (after call to copy) is (20, 33) ---Call to equals after call to copy: The 2 points are equal. = public class Point_Class{ int x,y; public Point_Class() { 3 }} public static void main(String[] args) { } public Point_Class(int x, int y) { this.x = x; this.y = y; } public int getXvalue() { return x; } public int getYvalue() { return y; } public void set(int x, int y) { this.x = x; this.y = y; } public void print(Point a) { System.out.println( toString(a) ); } public String toString(Point a) { return "( " + getXvalue() + + getYvalue () + } } public boolean equals(Point al, Point a2) { if(a1.x == a2.x && al.y == a2. y) { )"; public Point copy(Point a) { Point copyPoint = new Point(); copypoint.x = a.getXvalue(): copyPoint.y = a.getYvalue(); return copyPoint; } public Point getCopy (Point a) { return copy(a): } double d = Math.sqrt( (a.getXvalue() * a.getXvalue()) + (a.getYvalue() * a.getYvalue())); return d; ublic double distance(Point al, Point a2) { double d = Math.sqrt( Math.abs((Math.pow(a1.getXvalue(),2)-Math.pow(p2.getXvalue().2))) +Math.abs((Math.pow(a1.getYvalue(),2)-Math.pow(p2.9 return d; } public point translate(Point a, int amount) { a.set( a.getXvalue() + amount, a.getYvalue()+amount); return a; } public boolean isHorizontal(Point al, Point a2) { return (al.getYvalue() == a2.getYvalue()); } public boolean isVertical(Point al, Point a2) { return (al.getXvalue() == a2.getXvalue()); public double slope (Point al, Point a2) { double sl = (a2.getYvalue() - al.getYvalue()) / (a2.getXvalue() - a1.getXvalue()); return sl; e() * a.getXvalue()) + (a.getYvalue() * a.getYvalue())); t a2) { s((Math.pow(a1.getXvalue(),2)-Math.pow(p2.getXvalue(),2)))+Math.abs((Math.pow(a1.getYvalue(),2)-Math.pow(p2.getYvalue(),2)))); int amount) { a.getYvalue()+amount); a1, Point a2) { getYvalue()); Point a2) { etXvalue()); nt a2) { a1.getYvalue() / (a2.getXvalue() - a1.getXvalue()); public class Client public static void main(String [args) { Point a1=new Point(0,0); Point a2=new Point(7,13): Point a3=new Point(7,15); System.out.println("First Point:"+al.toString()); System.out.println("Second Point: "+a2.toString(): System.out.println("Third Point: "+a3.toString(); if(p2.isVertical(a3)) System.out.println("Second Point is "+a2.toString()+" lines up vertically with the third point "+a3.toString(); else System.out.println("Second Point is "+a2.toString()+" does not line up vertically the with third point "+a3.toString()); if(p2. isHorizontal (a3)) System.out.println("Second Point is "+a2.toString()+" lines up horizontally with the third point "+a3.toString()); else System.out.println("Second Point is "+p2.toString()+" does not line up horizontally with third point "+a3.toString(); int x,y: Scanner read=new Scanner(System.in); boolean flag=true; do 1 try 4 System.out.print(" Enter point 1 x coordinate: "); String tmp=read.next(); x=Integer.parseInt(tmp): if(x=0) System.out.println("ERROR! Should be positive."); else int x,y: Scanner read=new Scanner(System.in); boolean flag=true; do { { try { System.out.print(" Enter point 1 x coordinate: "); String tmp=read.next(): x=Integer.parseInt(tmp); if(x

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Are you exposed to any hazards or unusual working conditions?

Answered: 1 week ago