Loading...
Loading...
Loading...
A tile shop needs the area and the border length (perimeter) of each room it quotes for, and wants square rooms marked.
Write a class Rectangle with fields length and width and three methods: long area(), long perimeter() and boolean isSquare(). In main, create one Rectangle per room, set its fields after new, and print the results.
area perimeter, followed by SQUARE when the length equals the width.Example
Input
2 4 5 6 6
Output
20 18 36 24 SQUARE
A 4 × 5 room and a 6 × 6 square room.
Try the problem first. Open one hint at a time.
The fields are the data; each method only reads length and width and returns a value.
Use long fields: 10^9 × 10^9 does not fit in an int.
Build the line as a String and add SQUARE only when isSquare() is true.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor