Question

Write a program that collects the dimensions of two rectangles. For each rectangle, the program collects...

Write a program that collects the dimensions of two rectangles. For each rectangle, the program collects the width and length. Then, the program should print one of the following messages depending on the relative values of the rectangle sizes:

-          Rectangle 1 is bigger than Rectangle 2.

-          Rectangle 1 is the same size as Rectangle 2.

-          Rectangle 2 is bigger than Rectangle 1.

For example, consider the sample output of the proposed program (the bold font represents user input):

Please enter the width of Rectangle 1: 10

Please enter the length of Rectangle 1: 50

Please enter the width of Rectangle 2: 20

Please enter the length of Rectangle 2: 10

Rectangle 1 is bigger than Rectangle 2.

Assume that all dimensions are integers. The size (area) of a rectangle is the product of its length and width.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class RectangleEx {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Please enter the width of Rectangle 1:");
       int w1 = sc.nextInt();
       System.out.println("Please enter the length of Rectangle 1:");
       int l1 = sc.nextInt();
       System.out.println("Please enter the width of Rectangle 2:");
       int w2 = sc.nextInt();
       System.out.println("Please enter the length of Rectangle 2:");
       int l2 = sc.nextInt();
       int area1 = l1 * w1;
       int area2 = l2 * w2;
       if (area1 > area2)
           System.out.println("Rectangle 1 is bigger than Rectangle 2");
       else
           System.out.println("Rectangle 2 is bigger than Rectangle 1");
   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
Write a program that collects the dimensions of two rectangles. For each rectangle, the program collects...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using basic c++ write a separate code for each of the following: 1. Area Rectangle •...

    Using basic c++ write a separate code for each of the following: 1. Area Rectangle • Write a program that asks the user to enter length and width of a rectangle and then display the rectangles area. • Write the following functions • getLength – prompt the user to enter length and return that value as a double • getWidth – prompt the user to enter width and return that value as a double • getArea – This method should...

  • that can calculate several statistical measures of data. Write a program collects N integers from the...

    that can calculate several statistical measures of data. Write a program collects N integers from the user (N is a positive integer entered by the user). Then, the program prompts the user for an option: 1- to find the minimum, 2- to find the maximum, 3- to find the mean, 4-to find the standard deviation. In addition to the main method, your program must contain four methods with the following headers: The program public static int min(intlI A) public int...

  • Complete the Rectangle Program Using the code given in rectangle.cpp, implement the functions that are called...

    Complete the Rectangle Program Using the code given in rectangle.cpp, implement the functions that are called in the main function to complete the program. You must not change any of the existing code in the file. You can only add functions and comments to the code. Here’s a sample run of how the program should behave: Enter rectangle length: -1 ← invalid value, ask user to re-enter Enter rectangle length: -2 ← invalid value Enter rectangle length: 0 ← invalid...

  • using python3 Write a Python program that will ask the user for: 1. The length of...

    using python3 Write a Python program that will ask the user for: 1. The length of a rectangle. 2. The width of a rectangle and will print out the length of the diagonal of the rectangle. So your program should look like this: Please enter the length of the rectangle: Please enter the width of the rectangle: The diagonal of the rectangle is: So the user enters the length, width and then the answer is printed.

  • Write a program to display the area of a rectangle after accepting its length and width...

    Write a program to display the area of a rectangle after accepting its length and width from the user by means of the following functions: getLength – ask user to enter the length and return it as double getWidth – ask user to enter the width and return it as double getArea – pass width and length, compute area and return area displayArea – pass area and display it in this function. Expected Output: (i) Enter the length: 29 Enter...

  • 1. Define a class Rectangle with two attributes: (This is for C++) -length, an integer (default...

    1. Define a class Rectangle with two attributes: (This is for C++) -length, an integer (default value 1) -width, an integer (default value 1) Provide the following member functions: -default constructor -constructor that takes parameters used to initialize the data -get/set function for each attribute -a function perimeter that returns the perimeter of the rectangle -a function area that returns the area of the rectangle b. Write a program that uses the class Rectangle to create two rectangle objects with...

  • Exercise 9.2 Write a Python program that collects from the user a single integer. Have the...

    Exercise 9.2 Write a Python program that collects from the user a single integer. Have the program print “EVEN” if the integer is divisible by 2, and “ODD” if the integer is not divisible by two. [Use the % operator to compute the two’s modulus (remainder of division by two)] Exercise 9.3 Write a Python program that collects from the user two integers. Have the program print “Yes” if the two integers are BOTH greater than 10. Do nothing if...

  • please use c++ Write a program that contains a class Rectangle with two private double precision...

    please use c++ Write a program that contains a class Rectangle with two private double precision members iLength and iWidth, public set and get member functions for these two members, a two argument constructor that sets the length and width to any two user specified values and a void function area() that computes the area and then prints this value by inserting it into the cout output stream. Write a main function that ereates a Rectangle with a length of...

  • answer this question please, use java language Exercise 5: StyleOption program a) Modify the "StyleOption" program,...

    answer this question please, use java language Exercise 5: StyleOption program a) Modify the "StyleOption" program, in your lecture slides, to allow the user to specify the font name and size. Use combo boxes to obtain the font name and size (at least add four font name and 10 sizes) Style Options Say it with style! ]Bold Italic Make A Selection.... 26 b) Modify your solution in part 'a' such that it uses a slider to obtain the font size....

  • (NEED FULL CODE PLEASE)write a java program class to calculate and display the areas of 10 rectan...

    (NEED FULL CODE PLEASE)write a java program class to calculate and display the areas of 10 rectangles using arrays. * input validation sizes must be between 0-50 inches output to be displayed on the screen and send to an output file. *the output must appear in the following format. rectangle length width area 1    2.0    3.0    6.0 2 - - - - 10 display the rectangle with largest area. rectangle1 area= display the rectangle with smallest area. rectangle2 area=

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT