Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My assignment is to create a rectangle class in java. Create a MyRectangleClass There are two private instance variables, length l and width w with

My assignment is to create a rectangle class in java.

Create a MyRectangleClass

There are two private instance variables, length l and width w with double data type.

There is a constructor with two parameter

There are 4 public methods which are circumference, area, getWidth, and getLength.

circumference method will return circumference to the caller.(the formula for circumference is 2 *l + 2*w ) Area method Return the area to the caller(:l*w)

getLength method will return length to the caller.

getWidth method will return the width.

Declare another class with a main method to declare an object of a myRectangle and test all methods and print out result.

this is my class with all methods

public class MyRectangle { private double length; private double width; public void Rectangle (){} public void Rectangle(double l, double w){ length = l; width = w; } public double getLength(){ return length; } public double getWidth(){ return width; } public double getCircumference(){ return 2*l+w*2; } public double getArea(){ return l*w; } }

This is my class to test them.

import java.util.*;

public class RectangleManager{

public static void main(String[] args){ Rectangle r1 = new Rectangle(8,5); System.out.println("This is the area of the Rectangle: " + r1.getArea); System.out.println("This is the circumference of the Rectangle: " + r1.getcircumference); } }

For the first class, I keep getting an error with the area and circumference with using l and w. For the testing class, I get an error about the Rectangle.

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

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

Ehs 2.0 Revolutionizing The Future Of Safety With Digital Technology

Authors: Tony Mudd

1st Edition

B0CN69B3HW, 979-8867463663

More Books

Students also viewed these Databases questions

Question

Should Jessica qualify for a 504 Plan? Why or why not? (D10)

Answered: 1 week ago

Question

Explain the three sphere of quality with the help of diagram

Answered: 1 week ago