0% found this document useful (0 votes)
58 views3 pages

Rectangle

The document defines a Rectangle class with constructors and methods to get length, width, color and calculate area. It then creates an array of Rectangle objects, inputs values and stores areas in an array. It loops through to output each object and find the object with the largest area.

Uploaded by

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

Rectangle

The document defines a Rectangle class with constructors and methods to get length, width, color and calculate area. It then creates an array of Rectangle objects, inputs values and stores areas in an array. It loops through to output each object and find the object with the largest area.

Uploaded by

Iman Javed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

Scanner;
public class Rectangle{

private double length;


private double width;
private String color;

Rectangle(){
this.length = length;
this.width = width;
this.color = color;
}//no-args cons

Rectangle(double l, double w){


length =l;
width = w;
}//two - args cons

Rectangle(double width , double length , String color)


{
this.width = width;
this.length = length;
this.color = color;
}//three args cons

Rectangle(String c, double l, double w ){


color = c;
length =l;
width = w;

}//three - args with change sequence datatype cons

public double getlength()


{
return this.length;
}//getLength

public double getwidth()


{
return this.width;
}//getWidth

public String getcolor()


{
return this.color;
}//getColor

public void output()


{
System.out.println("\tLength : "+getlength());
System.out.println("\tWidth : "+getwidth());
System.out.println("\tArea is " +getlength()*getwidth());
}//output-method
public static void main(String[] args) {

Scanner in = new Scanner(System.in);

Rectangle [] rec = new Rectangle[10];

double length = 0;
double width = 0;
String color = "";

double [] store = new double[10];

for (int i=0; i<10; i++ )


{
System.out.println("\nEnter Values for Object "+(i+1)+ ": ");

System.out.print("\n\tEnter the Length: " );


length = in.nextDouble();

System.out.print("\tEnter the width: " );


width = in.nextDouble();

System.out.print("\tEnter the color: " );


in.nextLine();
color = in.nextLine();

System.out.println();

rec[i] = new Rectangle(width,length,color);

store[i] = rec[i].getwidth()*rec[i].getlength();

}//for-loop

for (int i = 0; i < 10 ; i++)


{
System.out.println("\nObject "+ (i+1));
rec[i].output();
}//for-loop

int check = 0;

for (int i = 0 ;i < 10 ; i++ )


{
if (i == 0) {

check = i;

}else if (store[check] < store[i] ) {


check = i;
} //if-else loop
}//for-loop
System.out.println("\n\tObject " + (check+1));

rec[check].output();

System.out.println("\n\tThe Largest area Object is '"+(check+1) +"' And area is


" +store[check]);

}//main
}//class

You might also like