Answer to Question #264559 in Java | JSP | JSF for Zach

Question #264559

Program Specifications Write a program to calculate the cost for replacing carpet for a single room. Carpet is priced by square foot. Total cost includes carpet, labor and sales tax. Dollar values are output with two decimals. For example, System.out.printf("Cost: $%.2f", cost);


Note: This program is designed for incremental development. Complete each step and submit for grading before starting the next step. Only a portion of tests pass after each step but confirm progress.

Step 1 (2 pts). Read from input the carpet price per square foot (double), room width (int) and room length (int). Calculate the room area in square feet. Calculate the carpet price based on square feet with an additional 20% for waste. Output square feet and carpet cost. Submit for grading to confirm 1 test passes.






1
Expert's answer
2021-11-12T17:36:52-0500
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
	    Scanner input=new Scanner(System.in);
	    System.out.println("Enter the price per Square foot");
	    double price=input.nextDouble();
		System.out.println("Enter the width");
		int w=input.nextInt();
		System.out.println("Enter the Length");
		int l=input.nextInt();
		double area=l*w;
		double total=area*price+(0.2*area*price);
		System.out.println("Area is "+area+" square feet");
		System.out.println("The total cost of the carpet is "+total);
	}
}

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