Bob a builder has come to you to build a program for his business. He needs to determine the square footage of a room in order to buy materials and calculate costs. Bob charges $125 per square metre. The program is going to ask the user to enter the name of a room. It will then ask for the width and length of the room (in meters) to be built. The program will calculate the room area and use this information to generate an approximate cost. Your program will display the room, the total area and the approximate cost to the screen.
Using Pseudocode, develop Javascript for this problem.
class Room {
constructor(name, width, length) {
this.name = name;
this.width = width;
this.length = length;
}
calcCost(price) {
return this.width * this.length * price
}
}
const kitchen = new Room('kitchen', 20, 10);
const pricePerSquareMeter = 125
const totalCosts = kitchen.calcCost(pricePerSquareMeter);
console.log(`The cost of materials for the ${kitchen.name} will be $ ${totalCosts} (1 square costs $ ${pricePerSquareMeter} per meter)`)
Comments
Leave a comment