Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The program below is to calculate the area of a rectangle. However, it produces error and/or incorrect results. 1) Explain where and why the


image text in transcribed 

The program below is to calculate the area of a rectangle. However, it produces error and/or incorrect results. 1) Explain where and why the program went wrong (use line numbers). 2) Fix the program to get accurate results. You don't have to rewrite the whole program, just explain how to fix them (use line numbers). 3 class shape { 4 456 private static int width; private static int height; 18 public class WhatWrong { 19 20 public static void main(String[] args) { 21 7 22 shape s1 = new shape(); 8 shape (int width, int height) { 23 9 width-width; 24 s1.width=2; s1.height=3; 10 height=height; 25 shape s2 = new shape(); 11 } 26 s2.width=4; 12 27 s2.height=5; 13 public int getArea() { 28 System.out.println(s1.getArea()); 14 return width*height; 15 } 16 } 17 12 29 30 31 32} System.out.println(s2.getArea()); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

The provided code has a few issues that prevent it from calculating the area of rectangles accurately Lets go through them Missing constructor The class shape has a constructor defined shapeint width ... 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

Step: 3

blur-text-image

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

Cost Management A Strategic Emphasis

Authors: Edward Blocher, David Stout, Paul Juras, Gary Cokins

7th edition

77733770, 978-0077733773

More Books

Students also viewed these Accounting questions

Question

Define deferred revenue. Why is it a liability?

Answered: 1 week ago