0% found this document useful (0 votes)
183 views5 pages

Experiment:1.4: Aim/Overview of The Practical

1. The document describes an experiment to write a Java program that creates two Rectangle objects, compares their area and color, and outputs whether they are matching or not. 2. It involves creating a Rectangle class with fields for length, width, area, and color, and methods to set the values and calculate area. 3. The main method creates two Rectangle objects, sets their attributes, compares the area and color, and prints "Matching Rectangles" if they match or "Non Matching Rectangles" if they do not match.

Uploaded by

Eknoor Singh
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)
183 views5 pages

Experiment:1.4: Aim/Overview of The Practical

1. The document describes an experiment to write a Java program that creates two Rectangle objects, compares their area and color, and outputs whether they are matching or not. 2. It involves creating a Rectangle class with fields for length, width, area, and color, and methods to set the values and calculate area. 3. The main method creates two Rectangle objects, sets their attributes, compares the area and color, and prints "Matching Rectangles" if they match or "Non Matching Rectangles" if they do not match.

Uploaded by

Eknoor Singh
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

EXPERIMENT:1.

1. Aim/Overview of the practical: Write a program in Java with class Rectangle with the data fields width,
length, area and color. The length, width and area are of double type and color is of string type. The methods are
set_length() , set_width() , set_color(), and find_area(). Create two object of Rectangle and compare their area
and color. If area and color same for the objects then display “Matching Rectangles” otherwise display “Non
Matching Rectangle”.

2. Task to be done: Write a program to find matching or non matching triangles.

3. Algorithm/Flowchart:

• Create a scanner class object


• Take 3 int variable length, width, area and one string variable
• Calculate
Check: -

 if color of rectangle 1 is same as rectangle 2


 Also if area of rectangle one is equal to area of triangle 2 is same
 Rectangles will be matching
 Print the result

4. Steps for experiment/practical:


• Set values
• create methods to calculate area
• Find output using conditional if statement
• Print the Result

5. CODE:

package java_lab;

class Rectangle
{

double length, width, area;

String color;

void set_length(double l)

length = l;

void set_width(double w)

width = w;

void set_color(String a)

color = a;

String getColor()

return color;

void find_area()

area = length * width;

double getArea()

{
return area;

public class area_rectangle_fourth

public static void main(String[] args)

Rectangle r1 = new Rectangle();

r1.set_length(5);

r1.set_width(5);

r1.set_color("red");

r1.find_area();

Rectangle r2 = new Rectangle();

r2.set_length(5);

r2.set_width(5);

r2.find_area();

r2.set_color("RED");

if (r1.getColor().equals(r2.getColor()) && r1.area == r2.area)

System.out.println("Matching Rectangles");

else

System.out.println("Non Matching Rectangles");

}
}

6. Image of sample output to be attached here

Learning outcomes (What I have learnt):


 Java Syntax

 Use of Conditional Statement

 Java Input and Output Functions


 Arithmetic operation and Math Class

Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1.
2.
3.

You might also like