0% found this document useful (0 votes)
6 views2 pages

Java Rectangle Area Calculation

This Java code defines a Rectangle class with private length and width variables. It includes constructors to initialize the rectangle with default values or specified length and width. Methods allow getting/setting the dimensions and calculating the area by multiplying length and width. A main method instantiates a rectangle with user-input dimensions and prints the calculated area.

Uploaded by

Azim Syahmi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Java Rectangle Area Calculation

This Java code defines a Rectangle class with private length and width variables. It includes constructors to initialize the rectangle with default values or specified length and width. Methods allow getting/setting the dimensions and calculating the area by multiplying length and width. A main method instantiates a rectangle with user-input dimensions and prints the calculated area.

Uploaded by

Azim Syahmi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

*;
public class Rectangle
{
private double length;
private double width;
Rectangle()
{
length=0.0;
width=0.0;
}
Rectangle(double x , double y)
{
length=x;
width=y;
}
double getlength()
{
return length;
}
double getwidth()
{
return width;
}
void setlength (double l)
{
length = l;
}
void setwidth (double w)
{
width = w;
}
double findArea()
{
double area;
area = length * width;
return area;
}
}

MAIN
import [Link].*;
public class RectangleApp
{
public static void main(String args[])
{
double c,d;
Scanner scan = new Scanner ([Link]);
c = [Link]();
d = [Link]();
Rectangle x = new Rectangle ( c,d);
[Link] ("Area of Rectangle:"+[Link] ());
}
}

You might also like