135k views
4 votes
Write a java program to help the company cover a room with the fewest pieces of carpet needed. The carpet squares all measure an integer number of feet on each edge, and only accepts jobs for rooms with both width (W) and length (L) in integer number of feet. Obviously if a room is perfectly square, the company can finish the job with a single piece of carpet, and the maximum number of carpet squares that would ever be needed is L x W squares, each 1-foot on a side

1 Answer

2 votes

Here is a sample Java program that calculates the minimum number of carpet squares needed to cover a room with a given width and length:

This program prompts the user to enter the width and length of the room in feet, and then calculates the minimum number of carpet squares needed to cover the floor. It does this by dividing the width and length of the room by the width and length of the carpet squares, and then rounding up to the nearest whole number. Finally, it prints the result to the console.

Note: In this program, the carpet squares are assumed to have a fixed width and length, which are represented by the variables carpetWidth and carpetLength. You will need to set these values to the appropriate dimensions for your carpet squares.

Write a java program to help the company cover a room with the fewest pieces of carpet-example-1
User Abedzantout
by
7.2k points