Question: class Square { //All data is private private double side, x, y; public Square(double side, double x, double y) { this.side = side; this.x =

class Square { //All data is private private double side, x, y; public Square(double side, double x, double y) { this.side = side; this.x = x; this.y = y; if((x >= side || y >= side) || (x <= 1 || y <= 1)) { System.out.println("Invalid X and Y Coordinates"); System.exit(0); } } //inner class class Drawer { public Drawer() { System.out.println("Drawer Initialized"); System.out.println("Drawing with side = " +side+ " x = " +x+ " y = " +y); } public void draw() { //Here row = 1 for(int col = 1; col <= side; col++) System.out.print("O"); System.out.println(); for(int row = 2; row <= side - 1; row++) { System.out.print("O"); for(int col = 2; col <= side - 1; col++) if(x == col && y == row) System.out.print("X"); else System.out.print(" "); System.out.println("O"); } //This is the last row for(int col = 1; col <= side; col++) System.out.print("O"); } } } public class DrawTest { public static void main(String[] args) { Square s1 = new Square(10, 5, 9); Square.Drawer d1 = s1.new Drawer(); d1.draw(); } }

Modify the above example so that it works for a rectangle, i.e. create a rectangle with specified width and height and then draw it alongwith the coordinates of a point x and y in the interior of the rectangle.

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!