Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; //importing scanner
- public class tiles { //program begins
- public static void main(String[] args) {
- /*
- *Write a program which enables a person to work out the cost of covering the floor of his house with tiles.
- * Data is supplied as follows:
- * (a) The number of rooms in the house (9)
- * (b) For each room:
- * (i) The size and cost of one tile to be used in that room
- * (ii) The length and breadth of the room.
- * For each room, calculate the number of tiles required, as well as the cost of the tiles.
- * At the end, print the total cost of the tiles required for the whole house.
- */
- Scanner input = new Scanner (System.in); //scanner declaration
- //variable declaration
- double length, breadth, room_area, one_room, tile_side1, tile_side2, tile_area, tile_cost, total_tile_cost, total_cost = 0;
- //for loop used to...
- for(double room=1; room<=9; room++) {
- //input statements so the user can enter the length and breadth of a room, size of the tile and its cost
- System.out.println("Length of room in meters: ");
- length = input.nextDouble();
- System.out.println("Breadth of room in meters: ");
- breadth = input.nextDouble();
- System.out.println("Length of one tile in meters: ");
- tile_side1 = input.nextDouble();
- System.out.println("Width of one tile in meters: ");
- tile_side2 = input.nextDouble();
- System.out.println("Cost of one tile: ");
- tile_cost = input.nextDouble();
- //calculating the area of each room
- room_area = length * breadth;
- //calculating the area of one tile
- tile_area = tile_side1 * tile_side2;
- //finding the amount of tiles needed for the room
- one_room = room_area / tile_area;
- //to find the cost to tile the room
- total_tile_cost = one_room * tile_cost;
- //total cost to tile all 9 rooms
- total_cost+=total_tile_cost;
- } //for loop ends
- //output statement to show the user the total cost
- System.out.println("The total cost of the tiles required for the house: " +total_cost);
- }
- } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement