Question: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Assume that the classes listed in the Java Quick Reference have

SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA.

  • Assume that the classes listed in the Java Quick Reference have been imported where appropriate.
  • Unless otherwise noted in the question, assume that parameters in method calls are notnulland that methods are called only when their preconditions are satisfied.
  • In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit.

This question involves theDrawclass, which is used to draw line segments and squares on a10

-by-10

xy

-coordinate grid.

public class Draw

{

/**Precondition:All parameters are between0and10,inclusive.

*Draws a line segment in a10

-by-10

xy

-coordinate grid.

*The line segment is drawn from(x1, y1)to(x2, y2).

*/

public void drawLine(int x1, int y1, int x2, int y2)

{ /*implementation not shown*/ }

/**Precondition:0 ? x 0.

*Draws a square on a10

-by-10

xy

-coordinate grid

*and prints the square's side length and area.

*The upper left corner of the square will be located

*at the coordinate(x, y)and the side length of the

*square will belen(or as large as will fit in the grid).

*/

public void drawSquare(int x, int y, int len)

{ /*to be implemented*/ }

}

ThedrawLinemethod, whose implementation is not shown, is used to draw a line segment from the coordinate(x1, y1)to the coordinate(x2, y2). For example, the calldrawLine(2, 5, 6, 4)will produce the figure below.

SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTENIN JAVA.Assume that the classes listed in the Java Quick Reference havebeen imported where appropriate.Unless otherwise noted in the question, assume that parametersin method calls are notnulland that methods are called only when their

\f\f\f\f

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 Programming Questions!