Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3) Consider the following class and then answer the questions that follows: public class Rectangle { private double length; private double width: private double area;

image text in transcribed
image text in transcribed
3) Consider the following class and then answer the questions that follows: public class Rectangle { private double length; private double width: private double area; public Rectangle(double I, double w) { length=; width=w; } public void calculate Areal) { area=length*width; public String toString() { return String.format("Length=%.2f%nWidth=%.2f%nArea=%.2f",leogth widthacea); 3 public double setlength() { return length; } public void setlength double length) { thisJength-length; } 3.1 In the space provided beneath the getLength() and setLength() methods, insert new accessor and mutator methods for the width instance variable. (1 Point) 3.2 Assume that after instantiating a Rectangle object and the area is calculated by calling the method calculate Area(), the length was lost due to calling the setLength() method with a different length (i.e., the original length was overwritten and hence lost). Define a new method called recoverLength() that is used to recover the length. Insert the new method following the methods you inserted in 3.1. Hint: Think of how you can use the area and other details provided to recover the length. (1.5 Point)

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

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

Students also viewed these Databases questions