Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//Find and correct all the errors in the following Java program. class Rectangle { private int height = 1; private int width = 1; public

//Find and correct all the errors in the following Java program. class Rectangle { private int height = 1; private int width = 1; public Rectangle(int height, int width) { height = this.height; width = this.width; } public void doubleHeight() { height += 2; } public void doubleWidth() { width *= 2; } public boolean isSquare() { return height = width; } public void draw() { for (int row = 0; row < width; row++) { for (int col = 0; col < height; col++) { System.out.println("X"); } System.out.println(); } } } class Driver { public static void main(String[] args) { Rectangle a = new Rectangle(3, 6); Rectangle b = new Rectangle(5, 3); a.doubleHeight; b.doubleWidth; if a.isSquare { System.out.println("First Rectangle is a square.") } else { System.out.println("First Rectangle is not a square.") } a.draw(); if b.isSquare { System.out.println("Second Rectangle is a square.") } else { System.out.println("Second Rectangle is not a square.") } b.draw(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions