Question: Submit Line.java to work with Client.java Rewrite Line.java and modify to fit Submission requirements: (Line.java is written below as well as Client.java) Submission requirements: 1.

Submit Line.java to work with Client.java

Rewrite Line.java and modify to fit Submission requirements: (Line.java is written below as well as Client.java)

Submission requirements:

1. Data fields listed at the top of the Class, and they are all private.

2. Fields are not initialized in these private declarations (Java defaults prevail).

3. The only exception to requirements 1-3 above are public static final constants, which never change.

4. Constructors (that's plural) follow the data field specifications, and those initialize all the fields.

5. Always have a default constructor that defines the assumed defaults for all fields (verify if needed).

6. There should be no redundant constructor code; so the multiple argument version is used for others with this() calls.

7. There should be no redundant method code; so a detailed math formula is in one place, then used by others.

8. Accessor methods are grouped together. Mutators are grouped together. There should be no random placements in Class.

9. System.out calls (and other extraneous TODO garbage) is removed. A data structure is a data structure, not a program!!!

Submit Line.java to work with Client.java Rewrite Line.java and modify to fit

Copy of Line.java:

public class Line { Point p1; Point p2; public Line(Point first, Point second) { p1=first; p2=second; } public Line() {} public Point getP1() { return p1; } // inline, not allowed in JAVA public Point getP2() { return p2; } public String toString() { return new String("[(" + p1.x + ", " + p1.y +"), ("+ p2.x+", "+p2.y + ")]"); } String print() { // TODO: omit System.out from most Classes, and NEVER submit TODO System.out.println(p1+" "+p2); return (p1+" "+p2); } void plot(Graphics gee) { gee.drawString("Hello World",100,100); gee.drawLine(p1.x, p1.y, p2.x, p2.y); } }

Copy of Client.java:

import java.awt.*; public class Client { public static void main(String[] args) { // "[(22, 3), (4, 7)]" from Practice-IT Line zero = new Line(); // REQUIRED you write with this(... called Line little = new Line(new Point(22,3), new Point(4,7)); Line other = new Line(new Point(100,100), new Point(200,200)); System.out.println(little.print());; System.out.println(zero); // From Chapter 3G DrawingPanel canvas = new DrawingPanel(200,200); Graphics golly = canvas.getGraphics(); little.plot(golly); other.plot(golly); // Some test code System.out.println(little.getP1()); System.out.println(little.getSlope()); // you write a method System.out.println(little.getLength()); // you write a method System.out.println(little.intersect(other)); // you write a method } }

Output Results:

Submission requirements: (Line.java is written below as well as Client.java) Submission requirements:

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!