The Westfield Carpet Company has asked you to write anapplication that calculate
ID: 3610191 • Letter: T
Question
The Westfield Carpet Company has asked you to write anapplication that calculates the price of carpeting for rectangularrooms. To calculate the price, you multiply the area of the floor(width times length) by the price per square foot of carpet. Forexample, the area of floor that is 12 feet long and 10 feet wide is120 square feet. To cover that floor with carpet that costs $8 persquare foot would cost $960. (12 x 10 x8 = 960.)
First, you should create a class named RoomDimension that hastwo fields: one for the length of the room and one for the width.The RoomDimension class should have a method that returns the areaof the room. (The area of the room is the room’s lengthmultiplied by the room’s width.)
Next you should create a RoomCarpet class that has aRoomDimension object as a field. It should also have a field forthe cost of the carpet per square foot. The RoomCarpet class shouldhave a method that returns the total cost of the carpet.
Once you have written these classes, use them in an applicationthat asks the user to enter the dimensions of a room and the priceper square foot of the desired carpeting. The application shoulddisplay the total cost of the carpet.
RoomCarpet
- Size :RoomDimension
- carpetCost: double
+ RoomCarpet ( dim : RoomDimension,cost : double )
+ getTotalCost() : double
+ toString() : String
RoomDimension
- length :double
- width :double
+ RoomDimension( len :double, w : double)
+ getArea() : double
+ toString() : String
RoomCarpet
- Size :RoomDimension
- carpetCost: double
+ RoomCarpet ( dim : RoomDimension,cost : double )
+ getTotalCost() : double
+ toString() : String
Explanation / Answer
Dear.... import java.util.Scanner; public class RoomDimension { public static final double LENGTH =12.0; public static final double WIDTH =10.0; public static void main(String[]args){
int lengthFt; int lengthIn; int lengthIn; int widthFt; int widthFt; int widthIn; int widthIn; double area; double area; Scanner input = new Scanner(System.in);
instructions();
System.out.print("Enter length feet: ");
lengthFt= input.nextInt();
System.out.println();
System.out.print("Enter length inches: ");
lengthIn = input.nextInt();
System.out.println();
System.out.print("Enterwidth feet: ");
widthFt= input.nextInt();
System.out.println();
System.out.print("Enter width inches: ");
widthIn = input.nextInt();
area = ((lengthFt + lengthIn / LENGTH) * (widthFt + widthIn /LENGTH)) / WIDTH; System.out.println(); System.out.println("For a room that is " + lengthFt + " feet," + lengthIn + " inches by " + widthFt + " feet, " + widthIn + " inches, you will need " + area + " square yardsof carpet."); } public static voidinstructions() { System.out.println(" calculates the amount of carpet"); System.out.println(" enter the length of the room in feet"); System.out.println("and inches (as integers), then the width infeet and inches"); System.out.println("number of square yards of carpetneeded."); System.out.println(); } } I hope it is useful toyou.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.