Advertisement
thotfrnk

tiles.java

Nov 29th, 2022
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.35 KB | None | 0 0
  1. import java.util.Scanner; //importing scanner
  2. public class tiles { //program begins
  3.     public static void main(String[] args) {
  4.  
  5.         /*
  6.         *Write a program which enables a person to work out the cost of covering the floor of his house with tiles.
  7.         * Data is supplied as follows:
  8.         * (a) The number of rooms in the house (9)
  9.         * (b) For each room:
  10.         * (i) The size and cost of one tile to be used in that room
  11.         * (ii) The length and breadth of the room.
  12.         * For each room, calculate the number of tiles required, as well as the cost of the tiles.
  13.         * At the end, print the total cost of the tiles required for the whole house.
  14.          */
  15.  
  16.         Scanner input = new Scanner (System.in); //scanner declaration
  17.  
  18.         //variable declaration
  19.         double length, breadth, room_area, one_room, tile_side1, tile_side2, tile_area, tile_cost, total_tile_cost, total_cost = 0;
  20.  
  21.         //for loop used to...
  22.         for(double room=1; room<=9; room++) {
  23.  
  24.             //input statements so the user can enter the length and breadth of a room, size of the tile and its cost
  25.             System.out.println("Length of room in meters: ");
  26.             length = input.nextDouble();
  27.  
  28.             System.out.println("Breadth of room in meters: ");
  29.             breadth = input.nextDouble();
  30.  
  31.             System.out.println("Length of one tile in meters: ");
  32.             tile_side1 = input.nextDouble();
  33.  
  34.             System.out.println("Width of one tile in meters: ");
  35.             tile_side2 = input.nextDouble();
  36.  
  37.             System.out.println("Cost of one tile: ");
  38.             tile_cost = input.nextDouble();
  39.  
  40.             //calculating the area of each room
  41.             room_area = length * breadth;
  42.  
  43.             //calculating the area of one tile
  44.             tile_area = tile_side1 * tile_side2;
  45.  
  46.             //finding the amount of tiles needed for the room
  47.             one_room = room_area / tile_area;
  48.  
  49.             //to find the cost to tile the room
  50.             total_tile_cost = one_room * tile_cost;
  51.  
  52.             //total cost to tile all 9 rooms
  53.             total_cost+=total_tile_cost;
  54.  
  55.         } //for loop ends
  56.  
  57.         //output statement to show the user the total cost
  58.         System.out.println("The total cost of the tiles required for the house: " +total_cost);
  59.     }
  60. } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement