Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
0 like 0 dislike
6k views
in JECRC University B.Tech(CSE-V Sem) Java Programming Lab by Goeduhub's Expert (5.8k points)
edited by

The length, width and area are of double type and colour is of string type. Create two objects of Rectangle and compare their area and colour. If the area and colour both are the same for the objects then display “Matching Rectangles”, otherwise display “Non-matching Rectangle”

Goeduhub's Top Online Courses @Udemy

For Indian Students- INR 360/- || For International Students- $9.99/-

S.No.

Course Name

 Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence || Labeled as Highest Rated Course by Udemy

Apply Coupon

2.

Complete Machine Learning & Data Science with Python| ML A-Z Apply Coupon

3.

Complete Python Programming from scratch | Python Projects Apply Coupon
    More Courses

1 Answer

0 like 0 dislike
by Goeduhub's Expert (5.8k points)
edited by
 
Best answer

Program Code

import java.io.*;

import java.util.*;

class Rect

{

  double width,length,area;

  String color;

  Scanner sc=new Scanner(System.in);

   Rect()

   {  

   System.out.print("Enter the length: ");

   length=sc.nextDouble();

   System.out.print("Enter the width: ");

   width=sc.nextDouble(); 

   System.out.print("Enter the color: ");

    color=sc.next();

    area=length*width;

    System.out.println("Area of Rectangle: "+area);

   }

}

class Demo

{

   public static void main(String arg[])

   {

   System.out.println("First Rectangle: ");

   Rect r1=new Rect();

   System.out.println("Second Rectangle: ");

   Rect r2=new Rect();

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

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

   else

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

   }

}

Output

First Rectangle:

Enter the length: 10.22

Enter the width: 12.22

Enter the color: blue

Area of Rectangle: 124.88840000000002

Second Rectangle:

Enter the length: 12.22

Enter the width: 10.22

Enter the color: blue

Area of Rectangle: 124.88840000000002

Matching Rectangle


For more JU V Sem Java Lab Experiments Click here


3.3k questions

7.1k answers

394 comments

4.6k users

Related questions

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...