Answer to Question #143077 in Java | JSP | JSF for Hamza saeed

Question #143077
Write a program that computes the cost of painting and installing carpet in a
room. Assume that the room has one door, two windows, and one bookshelf. Your program must do the following:
a. Prompts the user to enter, in feet, the length, width, and height of a
room. Read the dimensions of the room.
b. Prompts the user to enter the widths and heights, in feet, of the door,
each window, and the bookshelf. Read these quantities.
c. Prompts the user to enter the cost, per square foot, of painting the
walls. Read these quantities.
d. Prompts the user to enter of cost, per square foot, of installing carpet.
Read these quantities.
1
Expert's answer
2020-11-09T00:14:43-0500
import java.util.*;


public class Main
{
	public static void main(String[] args) {
		System.out.print("Enter height of room: ");
		double roomHeight = new Scanner(System.in).nextDouble();
		
		System.out.print("Enter width of room: ");
		double roomWidth = new Scanner(System.in).nextDouble();
		
		System.out.print("Enter length of room: ");
		double roomLength = new Scanner(System.in).nextDouble();
		
		System.out.print("Enter width of door: ");
		double doorWidth = new Scanner(System.in).nextDouble();
		
		System.out.print("Enter height of door: ");
		double doorHeight = new Scanner(System.in).nextDouble();
		
		System.out.print("Enter width of first window: ");
		double firstWindowWidth = new Scanner(System.in).nextDouble();
		
		System.out.print("Enter height of first window: ");
		double firstWindowHeight = new Scanner(System.in).nextDouble();
		
		System.out.print("Enter width of second window: ");
		double secondWindowWidth = new Scanner(System.in).nextDouble();
		
		System.out.print("Enter height of second window: ");
		double secondWindowHeight = new Scanner(System.in).nextDouble();
		
		System.out.print("Enter the cost, per square foot, of painting the walls: ");
		double wallsPaintingCost = new Scanner(System.in).nextDouble();
		
		System.out.print("Enter the cost, per square foot, of installing carpet: ");
		double installingCarpetCost = new Scanner(System.in).nextDouble();
		
		double totalWallsPaintingCost = 0;
		totalWallsPaintingCost += (2*roomLength*roomWidth + 2*roomLength*roomHeight + 2*roomWidth*roomWidth - 
		                                (firstWindowHeight*firstWindowWidth) - (secondWindowHeight*secondWindowWidth)
		                                - (doorHeight*doorWidth))
		                                *wallsPaintingCost;
		
		double totalCarpetInstallationCost = installingCarpetCost*roomLength*roomWidth;
		
		System.out.print(String.format("\n\nWalls painting cost: %.2f",totalWallsPaintingCost));
		System.out.print(String.format("\n\nCarpet installation cost: %.2f",totalCarpetInstallationCost));
		
		
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS