Call your project as CarpetCost
Write a Java to calculate the cost of installing carpeting into a new room. Your program should ask the user to enter a value for the room width (in metres), the room length (in metres) and then calculate and print the cost of the carpeting, the cost of installation, the taxes to be paid (PST (8%) , GST (7%)) and the final overall cost. The carpet cost is $24.95 per square yard and the installation fee is $6 per square metre. Format all money output to show two decimal places.
Note: 1 inch = 2.54 centimetres; 1 yard = 36 inches; 1 metre = 100 centimetres
2 Marks of the solution will be given to the the following:
Following Variable naming convention, documentation of your program and header file)
For Example:
Enter the width of the room (in metres): 4.2
Enter the length of the room (in metres): 6.5
Cost of carpeting = $814.63
Cost of installation = $163.80
PST = $78.27
GST = $68.49
Total Cost = $1125.19
Code in Java and Grade 11 terms
Ans
code:-
import java.util.*;
class MyClass {
public static void main(String[ ] args) {
//input
Scanner sc = new Scanner(System.in);
//input width
System.out.println("Enter the width of room(in meters): ");
double w=sc.nextDouble();
System.out.println("Enter the length of room(in meters): ");
//input length
double l=sc.nextDouble();
//compute carpet cost
double cc=w*l*24.95*100*100/(2.54*2.54*36*36);
String ccs=String.format("%.02f",cc);
System.out.println("Cost of carpeting = "+ccs);
double ic= w*l*6;
String ics=String.format("%.02f",ic);
//compute installation cost
System.out.println("Cost of installation = $"+ics);
double pst=0.08*(cc+ic);
double gst=0.07*(cc+ic);
//compute pst,gst,total cost
String psts=String.format("%.02f",pst);
String gsts=String.format("%.02f",gst);
System.out.println("PST = $"+psts);
System.out.println("GST = $"+gsts);
String tcs=String.format("%.02f",(cc+ic+gst+pst));
System.out.println("Total Cost = $"+tcs);
}
}
If any doubt ask in the comments.
Get Answers For Free
Most questions answered within 1 hours.