Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started