Your job is to add a method to the Picture class that will put centered black crosshairs into the Picture referred to by this. When myPict.crossHairs() is called, your code should change the completely white Picture labelled BEFORE to the one labelled AFTER. See image.

In order to do this, the computer must make several computations and it must be controlled by loops to repeat certain operations. The things you must program are listed AND NUMBERED here:

  • Get the Picture's height (with getHeight() ).
  • Get the Picture's width (with getWidth() ).
  • Compute half the height (approximately).
  • Compute half the width (approximately). Program two separate loops, NOT NESTED!
  • One for loop to blacken the correct row of Pixels. (The horizontal row or line should be only 1 Pixel wide.)
  • One for loop to blacken the correct column of Pixels. (The vertical column or line should be only 1 Pixel wide. )
  • Get one single Pixel pix of the horizontal row crosshair.
  • Get one single Pixel pix of the vertical column crosshair.
  • Actually blacken one Pixel in the horizontal row crosshair (use pix.setColor( Color.black ); or equivalent.
  • Actually blacken one Pixel in the vertical column crosshair.

Write Java code into the method, as complete and correct as you can make it;

Fill in the body of the crossHairs method on the next page, MAKE SURE YOU WRITE "(1)", "(2)", "(3)", "(4)", "(5)", "(6)", "(7)", "(8)", "(9)" and "(10)", AND clearly mark what (1), (2), ... (10) refer to.

Add to G&E's Picture class a method named DrawAnX and submit a Picture.java file that demonstrates your work is correct when we run it.

Level 1: void DrawAnX(int xCenter, int yCenter, int squareSideLength) Draws the X inside a square with given center and given length of each side.

Level 2: void DrawAnX(int Xcenter, int Ycenter, int width, int height) Draws the X inside a rectangle with given center and given lengths of its two sides. The lines must go from corner to corner, crossing near the middle. This takes a lot more math than the equal-side case!

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.