Compile and test your new version of Line class that you create and hand it in as Assignment 2. Update the documentation to reflect the changes you have made. A nice way to do this is to add a section after the existing documentation headed "Code Changes and Enhancements /*********** ********* This program demonstrates a simple "Line" class. Here, a Line class is defined with its properties and interface (i.e.. its methods). A main method (in TestLineDriver.java) then creates instances of this Line class and calls on the methods to demonstrate its behavior. .*......**.* import java.io.*; public class Line private int x1, yi, x2, y2: 1/coordinates of the line I/Constructor 1/Receives 4 integers which are the Line's start and end points. public Line(int xOne, int yone, int xTwo, int yTwo) { 1/ each of these validates its argument - see below. set.Xane(xOne); SesxaneyOne); Bexa(Two); sex wytwo); 11/ end constructor //***** ***** 1/method draw() calls another method called drawLine(). 1/which is assumed to be a graphics prinitive on the // system. However, since this program will be 1/run in console mode, a text description of the Line 1/will be displayed. 1/ public void draw() { drawLine(xi, yi, x2, y2); ) //*** 1/method drawLine() simulates drawing of a line for console mode. //It should describe all the important attributes of the line. //In a graphics mode program, we would delete this and use the //system's Graphics library drawLine(). // //method drawLine() simulates drawing of a line for console mode. //It should describe all the important attributes of the line. //in a graphics mode program, we would delete this and use the //system's Graphics library drawLine(). private void drawLine(int xl, int yl, int x2, int y2) { Sysu Rainha "Draw a line from * o - * .. and y of + y1) Syabalu berkata "to x of + x2 + and y of y2 >> = //Method settine) allows user to change the points of the //already existing Line. // public void setLine(int xone, int yone, int xtwo, int YTVO) Betanet One): setmaneYone): BXDR XTO): BUDSREYTWO); ) 11 -- the individual setxxxx methods that prevent // any line's coordinate from being offscreen. // In the event of an invalid toffscreen) value, that value is (silently) set to 0. public void setungint xone) if xone 639) x1 - 0 else x1 - xOne! //***** ***** public void astxanerint yone) { if (yone Ol yone > 479) yl - 01 else y1 - yone; *** public void 865xxerint xTVO) if (xTwo > 639 xTwo //**** 65.xeint ytvo) it ytvo > 479 11 ytvo 479 11 ytvo // Now for some "get Access methods to get individual values //*** public int petang public int ses XARI return xl:) { return yli) //***** publie int Sex ) { return x2; publie int ges.DER = return y2;) // end class Line Now we will code a driver program (see below) called TestLine with main() where execution w.ll begin. It is this class, and this code, that will create instances of the line and call its methods. As a test module, this code would be improved with additional Systs statements that explain what is being attempted and what the results should be, for example: *About to change 11 to an invalid value and then redraw it. Line position should not change: ** class TestLine public static void main(String args) { Line 11 - null, 12 - null; //declare 2 instances of Line class //create 1 Line object 11 - new Line (10, 10, 100, 100); //draw it 11.draw(); //change start point with valid values 11.setLine(), S. must). St.): I/draw it again with new start point 11.draw(); 1/try to change xone (**) to an illegal value WX3000) 17draw the line...X1 should now be zero 11.draw(); //ereate a second Line instance, or object 12 - new Line (100, 100, 400, 400) //draw 2nd line 12.draw() // set a new valid ytwo for line 2 SEXY479) //draw 2nd line again 12.draw(): // end of main // end class Tesco 1/set new valid ytvo for line 2 buts. 479); //draw 2nd line 12.draw(): //draw 2nd line again 12.draw); // end of main // end class TestLine First copy into linux the source code that your instructor will send you. The source code will be a copy of the above and put it in a Line.java file in a subdirectory as specified above. To compile it, type iaxac Line.java: Modify the above Java program to accomplish the following: 1) Add additional methods and variables to the Line class to implement the following behaviors: = a. Add a method called getLength(). Calculate and return (get) the length of a Line based on its coordinates. Do not add an instance variable to hold the length. Instead, you are asked to do all the math calculations in a single return statement. The method returns a double. The formula is satt((x1-x2)*(x1-x2)+(y1. y2)*(yl-y2)). You can use the java.lang. Math class for calculating the square root (The method in Math is ssut), you need to check the API doc for its usage). b. Add a method called getAngle(). Calculate and return (get) the angle of a Line, which is defined as the angle between that line and the horizontal line that starts from (xl, yl) and goes to right. Do this in a single return statement Return value is between -pi2 and pi/2.c.g.: If a line is from (10. 10) to (20,20), the angle is pi/4 (45 degree): If a line is from (10,10) to (15,5), then the angle is -pi4. Math class is again used. One way of calculating the angle is asin((y2-y1 Ylength). Add code to main() of TestLine Driver java to test these new features. 2) Write another class and add another constructor in the Line class. The class is called Two Point and should be in its own file called Two Point.jaxa. It is very simple: It has 2 public data members called x and y and a constructor that accepts two integer arguments and stores them in x and y. That's all there is to the class. It has no other methods Add another constructor for Line that will accept 2 Tua Point objects instead of 4 ints. This second Line CONSULT SHOWRI Simply call the first constructor and stores them in x and y. That's all there is to the class. It has 10 other methods. Add another constructor for Line that will accept 2 Tweet objects instead of 4 ints. This second Line constructor should simply call the first constructor (the one that accepts 4 ints). So extract the x and yints from each Two Point and send them on to the other constructor. Keyword "this" can be used to call one constructor from another. Add code to main() to test this new constructor. You need only test a successful case here 3) Add exception creation/throwing, passing and handling In your set methods in the Line class, instead of setting a coordinate to zero when an invalid value is encountered, now have the appropriate code detect invalid values and throw an Exception that will be caught by the calling code (ie the code in main() of TestLine that calls the method) To do so, the setters in Line class will detect the problem and throw the exception (new a generic Exception object with message passed in to its constructor). This Exception you generate is a "checked exception The code in main() of TestLine class will catch and handle the exception: . when trying to alter an existing Line's position with an invalid value (example:the driver code calls a "set" on a current Line object with an invalid value). In this case, simply display in your catch the error message and state that the Line was not moved (but you can still use the Line object later, since it already exists). when creating a new Line (example the driver program creates new Line object with an invalid constructor value). In this case, if the constructor fails, the calling (catching) code should just display the message about the failure and terminate the program with return code of 88 (System.exit(88):). **Test this feature last in the program, since nothing more will execute. **Thus, when you create a new line, or do a set on a line, this code needs to be inside of a try/catch. The catch wil execute if a bad value is trying to be passed in by the driver code that creates the new line or does a bad set So your driver code will have a series of try catches where you create a line or alter a line with a set. Most of the catch blocks will not be executed, but some will when an exception is thrown by the Line.class. The other code in the driver program will not need a try/catch. The two catch blacks that will be executed when you do a at and than COLLAR WIL VI I CILI ULAS will not be executed, but some will when an exception is thrown by the Line.class. The other code in the driver program will not need a try/eatch The two catch blocks that will be executed is when you do a catch for a bad "set", and then at the very end of your driver code when you construct a line with bad values in the constructor. You do not need to code your "gets" in a try/catch in the driver The output of the program should have informational messages after (and/or before) each operation so the user knows what is being attempted and what the result was. Reading the output from the program should make it clear to the reader what the sequence of operations was and what happened. Make use of information (which you should supply to every thrown exception) in each exception object's message. You will lose some credit if this is done poorly. Submit one version of the modified program which implements and tests all the features mentioned above via Blackboard. You only need to submit the java source files (eg. Line.java: TestLine java, Two Point.jaxa) along with a screen shot of your output. Remember to apply applicable coding, formatting, and documentation standards! SAMPLE OUTPUT Inglies doww a line fromx of 10 and y of 10 to x of 100 and y of 100 SUCCESS Ins-draw a line from of Sandy of 10 x of 100 and y of 100 SUCCESS --EXCEPTION: MY TRY CATCH CAUGHT A GENERIC EXCEPTION IN A SET METHOD FOR HAD VALUE OF XI FOR AN EXISTING LINE java.lang. Exception: Value 1000 Was out of Bounds Insies-draw a line from x of Sandy of to x of 100 and y of 100 SUCCESS Indalias daw a line from x of 100 any of 100 to x of 400 and y of 400 SUCCESS In siswa line from x of 100 and y of 100 to x of 400 and y of 479 SUCCESS The angle or line is 0,7853981633974462 The angle for line 2 is 0.9012349603521654 The length for time is 13435008843545003 The length for line 2 is 483 3642518846424 test 20 point Constructor X1-10 test 2 perind Constructor X2-5 test 2 pin Constructor Y1-100 test 20 point Constructor Y1 - 400 = EXCEPTION This try arch auchynhados Filali The length for line is 134.35028542541403 The length for line 2 is 4834642518546424 test 2D point Constructor XI - 10 test 2D point Constructor X2-5 test 2D point Contractor Y1 - 100 test 2D point Constructor YI-400 EXCEPTION This try catch caught a Generic Exception for a bed constructor-Failed to create a line with 4 invalid values leaving with 15 of 88 Java Result: 88 BUILD SUCCESSFUL (total time: 0 seconds) IMPORTANT Documentation - Read this carefully and follow these guidelines Programs must be neatly and consistently formatted and documented. Write your code for human readers who cannot read your mind. If someone has to ask you "What does this method do?or "What does this variable represent?" you have probably failed to do this well Here are a few things we will look for: stuff that does nothing or is not needed or is redundant code where you tried something but aren't using it anymore but it's still there (and maybe commented out) documentation from another program or a previous version of the program that is irrelevant or just plain wrong for this program the same code in more than one place - usually should be a method and called from several places inconsistent indenting: if you indent:) by 2 spaces in one place, indent by 2 everywhere don't indent too much. 2- 4 spaces is plenty. Don't use tabs. lack of spaces after operands (usually) and commas in argument lists (always) who wrote this pgm, and when, and what does it do. The "how does it work" filed II . ********.. This program demonstrates a simple "Line" class. Here, a Line class is defined with its properties and interface (i.e., its methods). A main method (in TestLine) then creates instances of this Line class and calls on the methods to demonstrate its behavior. ************* *************/ import java.io.*; public class Line below. private int xl, yi, x2, y2; //coordinates of the line //Constructor 1/Receives 4 integers which are the Line's start and end points. public Line(int xone, int yone, int xTwo, int yTwo) 11 each of these validates its argument - see setXOne (xOne); set Yone (yOne); setXTWO (Two); set YTWO (Two); } // end constructor // method draw() calls another method called drawLine() 1/which is assumed to be a graphics primitive on 1/system. However, since this program will be 1/run in console mode, a text description of the Line 1/will be displayed. // public void draw() { drawLine(x1, yi, x2, y2); the } 1/method drawLine() simulates drawing of a line for console mode. //It should describe all the important attributes of the line. 1/In a graphics mode program, we would delete this and use the I lovetam'e Cranbine harvinai 11 console mode. // It should describe all the important attributes of the line. //In a graphics mode program, we would delete this and use the 1/system's Graphics library drawLine(). // private void drawLine(int xi, int yi, int x2, int y2) { System.out.println("Draw a line from x of " + xl + and y of + yi); System.out.println("to x of + x2 + " and y of " + y2 + " "); > 1/Method setLine() allows user to change the points of the 1/already existing Line. public void setLine(int xone, int yone, int xTwo, int yTwo) { Bet80ne( 3One); set Yone (yone); set XTWO (Two); set YTWO (Two); } 11 -- the individual setxxxx methods that prevent // any line's coordinate from being offscreen. // In the event of an invalid (offscreen) value, // that value is (silently) set to 0. public void setxone(int xone) { if (xOne 639) xl - 0; else xl xOne; > public void setyone(int yone) { if (yone 479) y1 = 0; else yl - yone; } public void setXTwo(int xTwo) { if (XTWO > 639 || XTWO public void setyTwo(int yvo) { if (yTwo > 479 11 yTwo //Now for some to get y2 = 0; else y2 = yTwo; > 1/Now for some "get" Access methods to get individual values public int getxone) { return x; } public int getYone() { return yl; > public int getXTwo() { return x2; } public int getYTWO() { return y2; > } // end class Line /********** ************* Now we will define a driver program below called TestLine with main() where execution will begin. It is this class, and this code, that will create instances of the Line and call its methods. As a test module, this code would be improved with additional System.out.println() statements that explain what is being attempted and what the results should be, for example: "About to change 11 to an invalid value and then redraw it. Line position should not change: **/ ******** class TestLine { public static void main(String args[]) { Line 11 = null, 12 = null; 1/declare 2 instances of Line class //create 1 Line object 11 - new Line (10, 10, 100, 100); //draw it 11.draw(); 1/change start point with valid values 11.setLine(5, 5, 11.getXTwo(), 11.getYTWO()); //draw it again with new start point 11.draw(); I/try to change xone (xl) to an illegal value 11.setxone (3000) } // end class Line /********** Now we will define a driver program below called TestLine with main() where execution will begin. It is this class, and this code, that will create instances of the Line and call its methods. As a test module, this code would be improved with additional System.out.println() statements that explain what is being attempted and what the results should be, for example: "About to change 11 to an invalid value and then redraw it. Line position should not change: "*/ //******* class TestLine { public static void main(String args[]) { Line 11 = null, 12 = null; 1/declare 2 instances of Line class //create 1 Line object 11 = new Line (10, 10, 100, 100); //draw it 11.draw(); //change start point with valid values 11.setLine(5, 5, 11.getXTWO(), 11.getYTWO()); 1/draw it again with new start point 11.draw(); 1/try to change One (xl) to an illegal value 11. setxone (3000); //draw the line...xl should now be zero 11.draw(); 1/create a second Line instance, or object 12 = new Line (100, 100, 400, 400); //draw 2nd line 12.draw(); 1/set a new valid yTwo for line 2 12. set YTWO (479); 1/draw 2nd line again 12.draw(); } // end of main } // end class TestLine Compile and test your new version of Line class that you create and hand it in as Assignment 2. Update the documentation to reflect the changes you have made. A nice way to do this is to add a section after the existing documentation headed "Code Changes and Enhancements /*********** ********* This program demonstrates a simple "Line" class. Here, a Line class is defined with its properties and interface (i.e.. its methods). A main method (in TestLineDriver.java) then creates instances of this Line class and calls on the methods to demonstrate its behavior. .*......**.* import java.io.*; public class Line private int x1, yi, x2, y2: 1/coordinates of the line I/Constructor 1/Receives 4 integers which are the Line's start and end points. public Line(int xOne, int yone, int xTwo, int yTwo) { 1/ each of these validates its argument - see below. set.Xane(xOne); SesxaneyOne); Bexa(Two); sex wytwo); 11/ end constructor //***** ***** 1/method draw() calls another method called drawLine(). 1/which is assumed to be a graphics prinitive on the // system. However, since this program will be 1/run in console mode, a text description of the Line 1/will be displayed. 1/ public void draw() { drawLine(xi, yi, x2, y2); ) //*** 1/method drawLine() simulates drawing of a line for console mode. //It should describe all the important attributes of the line. //In a graphics mode program, we would delete this and use the //system's Graphics library drawLine(). // //method drawLine() simulates drawing of a line for console mode. //It should describe all the important attributes of the line. //in a graphics mode program, we would delete this and use the //system's Graphics library drawLine(). private void drawLine(int xl, int yl, int x2, int y2) { Sysu Rainha "Draw a line from * o - * .. and y of + y1) Syabalu berkata "to x of + x2 + and y of y2 >> = //Method settine) allows user to change the points of the //already existing Line. // public void setLine(int xone, int yone, int xtwo, int YTVO) Betanet One): setmaneYone): BXDR XTO): BUDSREYTWO); ) 11 -- the individual setxxxx methods that prevent // any line's coordinate from being offscreen. // In the event of an invalid toffscreen) value, that value is (silently) set to 0. public void setungint xone) if xone 639) x1 - 0 else x1 - xOne! //***** ***** public void astxanerint yone) { if (yone Ol yone > 479) yl - 01 else y1 - yone; *** public void 865xxerint xTVO) if (xTwo > 639 xTwo //**** 65.xeint ytvo) it ytvo > 479 11 ytvo 479 11 ytvo // Now for some "get Access methods to get individual values //*** public int petang public int ses XARI return xl:) { return yli) //***** publie int Sex ) { return x2; publie int ges.DER = return y2;) // end class Line Now we will code a driver program (see below) called TestLine with main() where execution w.ll begin. It is this class, and this code, that will create instances of the line and call its methods. As a test module, this code would be improved with additional Systs statements that explain what is being attempted and what the results should be, for example: *About to change 11 to an invalid value and then redraw it. Line position should not change: ** class TestLine public static void main(String args) { Line 11 - null, 12 - null; //declare 2 instances of Line class //create 1 Line object 11 - new Line (10, 10, 100, 100); //draw it 11.draw(); //change start point with valid values 11.setLine(), S. must). St.): I/draw it again with new start point 11.draw(); 1/try to change xone (**) to an illegal value WX3000) 17draw the line...X1 should now be zero 11.draw(); //ereate a second Line instance, or object 12 - new Line (100, 100, 400, 400) //draw 2nd line 12.draw() // set a new valid ytwo for line 2 SEXY479) //draw 2nd line again 12.draw(): // end of main // end class Tesco 1/set new valid ytvo for line 2 buts. 479); //draw 2nd line 12.draw(): //draw 2nd line again 12.draw); // end of main // end class TestLine First copy into linux the source code that your instructor will send you. The source code will be a copy of the above and put it in a Line.java file in a subdirectory as specified above. To compile it, type iaxac Line.java: Modify the above Java program to accomplish the following: 1) Add additional methods and variables to the Line class to implement the following behaviors: = a. Add a method called getLength(). Calculate and return (get) the length of a Line based on its coordinates. Do not add an instance variable to hold the length. Instead, you are asked to do all the math calculations in a single return statement. The method returns a double. The formula is satt((x1-x2)*(x1-x2)+(y1. y2)*(yl-y2)). You can use the java.lang. Math class for calculating the square root (The method in Math is ssut), you need to check the API doc for its usage). b. Add a method called getAngle(). Calculate and return (get) the angle of a Line, which is defined as the angle between that line and the horizontal line that starts from (xl, yl) and goes to right. Do this in a single return statement Return value is between -pi2 and pi/2.c.g.: If a line is from (10. 10) to (20,20), the angle is pi/4 (45 degree): If a line is from (10,10) to (15,5), then the angle is -pi4. Math class is again used. One way of calculating the angle is asin((y2-y1 Ylength). Add code to main() of TestLine Driver java to test these new features. 2) Write another class and add another constructor in the Line class. The class is called Two Point and should be in its own file called Two Point.jaxa. It is very simple: It has 2 public data members called x and y and a constructor that accepts two integer arguments and stores them in x and y. That's all there is to the class. It has no other methods Add another constructor for Line that will accept 2 Tua Point objects instead of 4 ints. This second Line CONSULT SHOWRI Simply call the first constructor and stores them in x and y. That's all there is to the class. It has 10 other methods. Add another constructor for Line that will accept 2 Tweet objects instead of 4 ints. This second Line constructor should simply call the first constructor (the one that accepts 4 ints). So extract the x and yints from each Two Point and send them on to the other constructor. Keyword "this" can be used to call one constructor from another. Add code to main() to test this new constructor. You need only test a successful case here 3) Add exception creation/throwing, passing and handling In your set methods in the Line class, instead of setting a coordinate to zero when an invalid value is encountered, now have the appropriate code detect invalid values and throw an Exception that will be caught by the calling code (ie the code in main() of TestLine that calls the method) To do so, the setters in Line class will detect the problem and throw the exception (new a generic Exception object with message passed in to its constructor). This Exception you generate is a "checked exception The code in main() of TestLine class will catch and handle the exception: . when trying to alter an existing Line's position with an invalid value (example:the driver code calls a "set" on a current Line object with an invalid value). In this case, simply display in your catch the error message and state that the Line was not moved (but you can still use the Line object later, since it already exists). when creating a new Line (example the driver program creates new Line object with an invalid constructor value). In this case, if the constructor fails, the calling (catching) code should just display the message about the failure and terminate the program with return code of 88 (System.exit(88):). **Test this feature last in the program, since nothing more will execute. **Thus, when you create a new line, or do a set on a line, this code needs to be inside of a try/catch. The catch wil execute if a bad value is trying to be passed in by the driver code that creates the new line or does a bad set So your driver code will have a series of try catches where you create a line or alter a line with a set. Most of the catch blocks will not be executed, but some will when an exception is thrown by the Line.class. The other code in the driver program will not need a try/catch. The two catch blacks that will be executed when you do a at and than COLLAR WIL VI I CILI ULAS will not be executed, but some will when an exception is thrown by the Line.class. The other code in the driver program will not need a try/eatch The two catch blocks that will be executed is when you do a catch for a bad "set", and then at the very end of your driver code when you construct a line with bad values in the constructor. You do not need to code your "gets" in a try/catch in the driver The output of the program should have informational messages after (and/or before) each operation so the user knows what is being attempted and what the result was. Reading the output from the program should make it clear to the reader what the sequence of operations was and what happened. Make use of information (which you should supply to every thrown exception) in each exception object's message. You will lose some credit if this is done poorly. Submit one version of the modified program which implements and tests all the features mentioned above via Blackboard. You only need to submit the java source files (eg. Line.java: TestLine java, Two Point.jaxa) along with a screen shot of your output. Remember to apply applicable coding, formatting, and documentation standards! SAMPLE OUTPUT Inglies doww a line fromx of 10 and y of 10 to x of 100 and y of 100 SUCCESS Ins-draw a line from of Sandy of 10 x of 100 and y of 100 SUCCESS --EXCEPTION: MY TRY CATCH CAUGHT A GENERIC EXCEPTION IN A SET METHOD FOR HAD VALUE OF XI FOR AN EXISTING LINE java.lang. Exception: Value 1000 Was out of Bounds Insies-draw a line from x of Sandy of to x of 100 and y of 100 SUCCESS Indalias daw a line from x of 100 any of 100 to x of 400 and y of 400 SUCCESS In siswa line from x of 100 and y of 100 to x of 400 and y of 479 SUCCESS The angle or line is 0,7853981633974462 The angle for line 2 is 0.9012349603521654 The length for time is 13435008843545003 The length for line 2 is 483 3642518846424 test 20 point Constructor X1-10 test 2 perind Constructor X2-5 test 2 pin Constructor Y1-100 test 20 point Constructor Y1 - 400 = EXCEPTION This try arch auchynhados Filali The length for line is 134.35028542541403 The length for line 2 is 4834642518546424 test 2D point Constructor XI - 10 test 2D point Constructor X2-5 test 2D point Contractor Y1 - 100 test 2D point Constructor YI-400 EXCEPTION This try catch caught a Generic Exception for a bed constructor-Failed to create a line with 4 invalid values leaving with 15 of 88 Java Result: 88 BUILD SUCCESSFUL (total time: 0 seconds) IMPORTANT Documentation - Read this carefully and follow these guidelines Programs must be neatly and consistently formatted and documented. Write your code for human readers who cannot read your mind. If someone has to ask you "What does this method do?or "What does this variable represent?" you have probably failed to do this well Here are a few things we will look for: stuff that does nothing or is not needed or is redundant code where you tried something but aren't using it anymore but it's still there (and maybe commented out) documentation from another program or a previous version of the program that is irrelevant or just plain wrong for this program the same code in more than one place - usually should be a method and called from several places inconsistent indenting: if you indent:) by 2 spaces in one place, indent by 2 everywhere don't indent too much. 2- 4 spaces is plenty. Don't use tabs. lack of spaces after operands (usually) and commas in argument lists (always) who wrote this pgm, and when, and what does it do. The "how does it work" filed II . ********.. This program demonstrates a simple "Line" class. Here, a Line class is defined with its properties and interface (i.e., its methods). A main method (in TestLine) then creates instances of this Line class and calls on the methods to demonstrate its behavior. ************* *************/ import java.io.*; public class Line below. private int xl, yi, x2, y2; //coordinates of the line //Constructor 1/Receives 4 integers which are the Line's start and end points. public Line(int xone, int yone, int xTwo, int yTwo) 11 each of these validates its argument - see setXOne (xOne); set Yone (yOne); setXTWO (Two); set YTWO (Two); } // end constructor // method draw() calls another method called drawLine() 1/which is assumed to be a graphics primitive on 1/system. However, since this program will be 1/run in console mode, a text description of the Line 1/will be displayed. // public void draw() { drawLine(x1, yi, x2, y2); the } 1/method drawLine() simulates drawing of a line for console mode. //It should describe all the important attributes of the line. 1/In a graphics mode program, we would delete this and use the I lovetam'e Cranbine harvinai 11 console mode. // It should describe all the important attributes of the line. //In a graphics mode program, we would delete this and use the 1/system's Graphics library drawLine(). // private void drawLine(int xi, int yi, int x2, int y2) { System.out.println("Draw a line from x of " + xl + and y of + yi); System.out.println("to x of + x2 + " and y of " + y2 + " "); > 1/Method setLine() allows user to change the points of the 1/already existing Line. public void setLine(int xone, int yone, int xTwo, int yTwo) { Bet80ne( 3One); set Yone (yone); set XTWO (Two); set YTWO (Two); } 11 -- the individual setxxxx methods that prevent // any line's coordinate from being offscreen. // In the event of an invalid (offscreen) value, // that value is (silently) set to 0. public void setxone(int xone) { if (xOne 639) xl - 0; else xl xOne; > public void setyone(int yone) { if (yone 479) y1 = 0; else yl - yone; } public void setXTwo(int xTwo) { if (XTWO > 639 || XTWO public void setyTwo(int yvo) { if (yTwo > 479 11 yTwo //Now for some to get y2 = 0; else y2 = yTwo; > 1/Now for some "get" Access methods to get individual values public int getxone) { return x; } public int getYone() { return yl; > public int getXTwo() { return x2; } public int getYTWO() { return y2; > } // end class Line /********** ************* Now we will define a driver program below called TestLine with main() where execution will begin. It is this class, and this code, that will create instances of the Line and call its methods. As a test module, this code would be improved with additional System.out.println() statements that explain what is being attempted and what the results should be, for example: "About to change 11 to an invalid value and then redraw it. Line position should not change: **/ ******** class TestLine { public static void main(String args[]) { Line 11 = null, 12 = null; 1/declare 2 instances of Line class //create 1 Line object 11 - new Line (10, 10, 100, 100); //draw it 11.draw(); 1/change start point with valid values 11.setLine(5, 5, 11.getXTwo(), 11.getYTWO()); //draw it again with new start point 11.draw(); I/try to change xone (xl) to an illegal value 11.setxone (3000) } // end class Line /********** Now we will define a driver program below called TestLine with main() where execution will begin. It is this class, and this code, that will create instances of the Line and call its methods. As a test module, this code would be improved with additional System.out.println() statements that explain what is being attempted and what the results should be, for example: "About to change 11 to an invalid value and then redraw it. Line position should not change: "*/ //******* class TestLine { public static void main(String args[]) { Line 11 = null, 12 = null; 1/declare 2 instances of Line class //create 1 Line object 11 = new Line (10, 10, 100, 100); //draw it 11.draw(); //change start point with valid values 11.setLine(5, 5, 11.getXTWO(), 11.getYTWO()); 1/draw it again with new start point 11.draw(); 1/try to change One (xl) to an illegal value 11. setxone (3000); //draw the line...xl should now be zero 11.draw(); 1/create a second Line instance, or object 12 = new Line (100, 100, 400, 400); //draw 2nd line 12.draw(); 1/set a new valid yTwo for line 2 12. set YTWO (479); 1/draw 2nd line again 12.draw(); } // end of main } // end class TestLine