Edit the following program. instructions are below. using java. import java.util
ID: 3705897 • Letter: E
Question
Edit the following program.
instructions are below.
using java. import java.util.Scanner;
Do not use objects.
Do not use;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
use good comments.
import java.util.Scanner;
public class DemoRoom
{
private static double paintingCostPerSqFt=1;
private static double flooringWithLinoleumTileCost=1;
private static double flooringWithCarpetCost=2;
private static double flooringWithHardwoodCost=3;
private static double flooringWithCeramicTileCost=4;
private static double r_length; //Room Length
private static double r_width ; //Room Width
private static double r_height; //Room Height
private static double d_width; //Door Width
private static double d_height; //Door Height
private static double w1_width; //Window1 Width
private static double w1_height; //Window1 Height
private static double w2_width; //Window1 Width
private static double w2_height; //Window1 Height
private static double b_width; //Bookshelf Width
private static double b_height; //Bookshelf Height
private static double b_depth; //Bookshelf Depth
private static int customerPreferenceRenovation1=0;
private static double customerBudgetRenovation1;
private static int customerPreferenceRenovation2=0;
private static double customerBudgetRenovation2;
private static int customerPreferenceRenovation3=0;
private static double customerBudgetRenovation3;
public static void main(String args[])
{
//To get the user input from the console
Scanner sc = new Scanner(System.in);
//Carpeting and Painting includes for Room, Door and Windows
//Getting the measurements from the user through console for all three - Room, Door, Windows, BookShelf
//Getting User Inputs for a Room
System.out.println("Enter Room length, width and height :");
double r_length = sc.nextDouble();
double r_width = sc.nextDouble();
double r_height = sc.nextDouble();
//Getting User Inputs for a Door
System.out.println("Enter Door width and height :");
d_width = sc.nextDouble();
d_height = sc.nextDouble();
//Getting User Inputs for the first Window
System.out.println("Enter Window1's length, width and height :");
w1_width = sc.nextDouble();
w1_height = sc.nextDouble();
//Getting User Inputs for the second Window
System.out.println("Enter Window2's length, width and height :");
w2_width = sc.nextDouble();
w2_height = sc.nextDouble();
System.out.println("Enter bookshelf width, height,depth :");
b_width = sc.nextDouble();
b_height = sc.nextDouble();
b_depth = sc.nextDouble();
//Calculate all the Areas
double r_area=calculateRoomArea(r_length, r_width,r_height);
double w1_area=calculateWindowArea(w1_width,w1_height);
double w2_area=calculateWindowArea(w2_width,w2_height);
double d_area =calculateDoorArea(d_width,d_height);
double b_area = calculateBookShelfArea(b_width,b_height);
double b_floor_area = calculateBookShelfFloorArea(b_depth,b_width);
double r_floor_area = calculateRoomFloorArea(r_length,r_width);
//Calculate Total area for painting and carpeting
double total_area_painting = r_area - (w1_area + w2_area + d_area + b_area);
double total_area_carpeting = r_floor_area - b_floor_area;
double total_cost_painting = calculatTotalPaintingCost(total_area_painting);
System.out.println("Flooring Preferences::");
System.out.println("0-Anything is Fine");
System.out.println("1-Ceramic Tile");
System.out.println("2-Hardwood");
System.out.println("3-Carpet");
System.out.println("4-Linoleum Tile");
System.out.println("For Renovation 1 : Please enter the flooring preference as above and also the total budget:");
customerPreferenceRenovation1 = sc.nextInt();
customerBudgetRenovation1 = sc.nextDouble();
String customerPreferenceRenovation1AsText = displayCustomerFlooringPrefAsText(customerPreferenceRenovation1);
System.out.println("Your have chosen for flooring for Renovation1: "+customerPreferenceRenovation1AsText);
System.out.println("Your Expected Budget for Renovation1: "+customerBudgetRenovation1);
System.out.println("Our Actual Budget For Painting for Renovation1: "+total_cost_painting);
System.out.println("Our Actual Budget For Flooring for Renovation1: "+calculateTotalFlooringCostBasedOnCustomerPreference(customerPreferenceRenovation1,total_area_carpeting));
System.out.println("For Renovation 2 : Please enter the flooring preference as above and also the total budget:");
customerPreferenceRenovation2 = sc.nextInt();
customerBudgetRenovation2 = sc.nextDouble();
String customerPreferenceRenovation2AsText = displayCustomerFlooringPrefAsText(customerPreferenceRenovation2);
System.out.println("Your have chosen for flooring for Renovation2: "+customerPreferenceRenovation2AsText);
System.out.println("Your Expected Budget for Renovation2: "+customerBudgetRenovation2);
System.out.println("Our Actual Budget For Painting for Renovation2: "+total_cost_painting);
System.out.println("Our Actual Budget For Flooring for Renovation2: "+calculateTotalFlooringCostBasedOnCustomerPreference(customerPreferenceRenovation2,total_area_carpeting));
System.out.println("For Renovation 3 : Please enter the flooring preference as above and also the total budget:");
customerPreferenceRenovation3 = sc.nextInt();
customerBudgetRenovation3 = sc.nextDouble();
String customerPreferenceRenovation3AsText = displayCustomerFlooringPrefAsText(customerPreferenceRenovation3);
System.out.println("Your have chosen for flooring for Renovation3: "+customerPreferenceRenovation3AsText);
System.out.println("Your Expected Budget for Renovation3: "+customerBudgetRenovation3);
System.out.println("Our Actual Budget For Painting for Renovation3: "+total_cost_painting);
System.out.println("Our Actual Budget For Flooring for Renovation3: "+calculateTotalFlooringCostBasedOnCustomerPreference(customerPreferenceRenovation3,total_area_carpeting));
}
public static double calculateRoomArea(double length, double width,double height)
{
return 2 * r_length * r_height + 2 * r_height * r_width
+ r_length * r_width;
}
public static double calculateDoorArea(double width,double height)
{
return height*width;
}
public static double calculateWindowArea(double width,double height)
{
return height*width;
}
public static double calculateBookShelfArea(double width,double height)
{
return height*width;
}
public static double calculateBookShelfFloorArea(double width,double depth)
{
return depth*width;
}
public static double calculateRoomFloorArea(double length, double width)
{
return length*width;
}
public static double calculatTotalPaintingCost(double totalAreaPainting)
{
return totalAreaPainting*paintingCostPerSqFt;
}
public static double calculateTotalFlooringCostBasedOnCustomerPreference(int customerFlooringPreference, double totalAreaCarpeting)
{
double calculatedFlooringCost;
switch(customerFlooringPreference)
{
case 1:
calculatedFlooringCost = calculateTotalCeramicTileFlooringCost(totalAreaCarpeting); //Cost=4$/Sq.ft
break;
case 2:
calculatedFlooringCost = calculateTotalHardwoodFlooringCost(totalAreaCarpeting); //Cost=3$/Sq.ft
break;
case 3:
calculatedFlooringCost = calculateTotalCarpetFlooringCost(totalAreaCarpeting); //Cost=2$/Sq.ft
break;
case 4:
calculatedFlooringCost = calculateTotalLinoleumTileFlooringCost(totalAreaCarpeting); //The least expensive one Cost=1$/Sq.ft
break;
default:
calculatedFlooringCost = calculateTotalCeramicTileFlooringCost(totalAreaCarpeting); //The most expensive one Cost=4$/Sq.ft
}
return calculatedFlooringCost;
}
public static double calculateTotalCeramicTileFlooringCost(double totalAreaCarpeting)
{
return totalAreaCarpeting*flooringWithCeramicTileCost;
}
public static double calculateTotalHardwoodFlooringCost(double totalAreaCarpeting)
{
return totalAreaCarpeting*flooringWithHardwoodCost;
}
public static double calculateTotalCarpetFlooringCost(double totalAreaCarpeting)
{
return totalAreaCarpeting*flooringWithCarpetCost;
}
public static double calculateTotalLinoleumTileFlooringCost(double totalAreaCarpeting)
{
return totalAreaCarpeting*flooringWithLinoleumTileCost;
}
public static String displayCustomerFlooringPrefAsText(int flooringPrefNumber)
{
String flooringPreference ="Anything is fine";
switch(flooringPrefNumber)
{
case 1:
flooringPreference ="Ceramic Tile";
break;
case 2:
flooringPreference ="Hardwood";
break;
case 3:
flooringPreference ="Carpet";
break;
case 4:
flooringPreference ="Linoleum tile";
break;
default:
flooringPreference ="Anything is fine";
}
return flooringPreference;
}
}
*************************
Change the code of the above program to where NOW the number of doors, windows and book cases is not known. Thus you will ask for the DIMENSIONS of the room and the number of DOORS, WINDOWS AND BOOKCASES.
• Then use the information to read in the DIMENSIONS and calculate the number of square feet of wall and flooring that will need to be worked. To test the program run the program three times entering the data below . The output will be the number square feet wall space and floor space along with the cost of doing the walls and floors . Use data below on the selections for the flooring. (NOTE: only thing changing from HW2 is that you will be dynamically asking for and using the doors, windows and bookcases – rest of the problem stays the same.
• After subtracting the cost of the floor from the floor budget (THERE IS NO WALL BUDGET) output how much money is left from the floor budget.
· First renovation project (THREE DOORS, ONE BOOKSHELF, NO WINDOWS)
o Room is 12 feet long, 12 feet wide, and 12 feet high
o Door 1 is 2 feet wide by 10 feet high
o Door 2 is 3 feet wide by 5 feet high
o Door 3 is 3 feet wide by 5 feet high
o Bookshelf is 8 feet long by 10 feet high by 2 feet deep
o No windows
· Second renovation project (3 WINDOWS, 2 BOOKSHELFS, NO DOORS)
o Room is 24 feet long, 12 feet wide, and 8 feet high
o Window 1 is 2 feet wide by 6 feet high
o Window 2 is 3 feet wide by 5 feet high
o Window 3 is 8 feet wide by 5 feet high
o Bookshelf 1 is 8 feet long by 6 feet high by 3 feet deep
o Bookshelf 2 is 3 feet long by 6 feet high by 2 feet deep
o No doors
· Third renovation project (ONE DOOR, 2 WINDOWSS, ONE BOOKSHELF)
o Room is 12.75 feet long, 11.25 feet wide, and 12 feet high
o Door is 1.95 feet wide by 10 feet high
o Window 1 is 2.5 feet wide by 5 feet high
o Window 2 is 6.8 feet wide by 7.2 feet high
o Bookshelf is 8 feet long by 6 feet high by 3 feet deep
Floor budget and preferences
For all three renovation projects from Project 1 use Tile= $4.00 /sq ft; Wood = $3.00/ sq ft; Carpet = $2.00/ sq ft and linoleum = $1.00/sq ft).
Use the following as the budget and preference:
Budget/preference
Renovation 1
Renovation 2
Renovation 3
User preference
0
1
3
Budget
800.00
200.00
400.00
Budget/preference
Renovation 1
Renovation 2
Renovation 3
User preference
0
1
3
Budget
800.00
200.00
400.00
Explanation / Answer
here is your program : --------------->>>>>>>>
import java.util.Scanner;
public class DemoRoom
{
private static double paintingCostPerSqFt=1;
private static double flooringWithLinoleumTileCost=1;
private static double flooringWithCarpetCost=2;
private static double flooringWithHardwoodCost=3;
private static double flooringWithCeramicTileCost=4;
private static double r_length; //Room Length
private static double r_width ; //Room Width
private static double r_height; //Room Height
private static double d_width; //Door Width
private static double d_height; //Door Height
private static double door_area = 0;
private static double w_width; //Window1 Width
private static double w_height; //Window1 Height
private static double window_area = 0;
private static double b_width; //Bookshelf Width
private static double b_height; //Bookshelf Height
private static double b_depth; //Bookshelf Depth
private static double self_area = 0;
private static double self_floor_area = 0;
private static int customerPreferenceRenovation1=0;
private static double customerBudgetRenovation1;
private static int customerPreferenceRenovation2=0;
private static double customerBudgetRenovation2;
private static int customerPreferenceRenovation3=0;
private static double customerBudgetRenovation3;
public static void main(String args[])
{
//To get the user input from the console
Scanner sc = new Scanner(System.in);
//Carpeting and Painting includes for Room, Door and Windows
//Getting the measurements from the user through console for all three - Room, Door, Windows, BookShelf
//Getting User Inputs for a Room
System.out.println("Enter Room length, width and height :");
r_length = sc.nextDouble();
r_width = sc.nextDouble();
r_height = sc.nextDouble();
//Getting User Inputs for a Door
System.out.println("Enter How many door : ");
int no_of_door = sc.nextInt();
for(int i = 0;i<no_of_door;i++){
System.out.println(" Enter Door"+(i+1)+" width and height :");
d_width = sc.nextDouble();
d_height = sc.nextDouble();
door_area = door_area + calculateDoorArea(d_width,d_height);
}
//Getting User Inputs for the first Window
System.out.println("Enter how many windows : ");
int no_of_window = sc.nextInt();
for(int i = 0;i<no_of_window;i++){
System.out.println(" Enter window"+(i+1)+"'s width and height :");
w_width = sc.nextDouble();
w_height = sc.nextDouble();
window_area = window_area + calculateWindowArea(w_width,w_height);
}
//Getting User Inputs for the second Window
System.out.println("Enter how many Bookshelf : ");
int no_of_bself = sc.nextInt();
for(int i = 0;i<no_of_bself;i++){
System.out.println("Enter bookshelf width, height,depth :");
b_width = sc.nextDouble();
b_height = sc.nextDouble();
b_depth = sc.nextDouble();
self_area = self_area + calculateBookShelfArea(b_width,b_height);
self_floor_area = self_floor_area + calculateBookShelfFloorArea(b_width,b_depth);
}
//Calculate all the Areas
double r_area=calculateRoomArea();
double r_floor_area = calculateRoomFloorArea();
//Calculate Total area for painting and carpeting
double total_area_painting = r_area - (window_area + door_area + self_area);
double total_area_carpeting = r_floor_area - self_floor_area;
double total_cost_painting = calculatTotalPaintingCost(total_area_painting);
System.out.println("Flooring Preferences::");
System.out.println("0-Anything is Fine");
System.out.println("1-Ceramic Tile");
System.out.println("2-Hardwood");
System.out.println("3-Carpet");
System.out.println("4-Linoleum Tile");
System.out.println("For Renovation 1 : Please enter the flooring preference as above and also the total budget:");
customerPreferenceRenovation1 = sc.nextInt();
customerBudgetRenovation1 = sc.nextDouble();
String customerPreferenceRenovation1AsText = displayCustomerFlooringPrefAsText(customerPreferenceRenovation1);
System.out.println("Your have chosen for flooring for Renovation1: "+customerPreferenceRenovation1AsText);
System.out.println("Your Expected Budget for Renovation1: "+customerBudgetRenovation1);
System.out.println("Our Actual Budget For Painting for Renovation1: "+total_cost_painting);
System.out.println("Our Actual Budget For Flooring for Renovation1: "+calculateTotalFlooringCostBasedOnCustomerPreference(customerPreferenceRenovation1,total_area_carpeting));
System.out.println("For Renovation 2 : Please enter the flooring preference as above and also the total budget:");
customerPreferenceRenovation2 = sc.nextInt();
customerBudgetRenovation2 = sc.nextDouble();
String customerPreferenceRenovation2AsText = displayCustomerFlooringPrefAsText(customerPreferenceRenovation2);
System.out.println("Your have chosen for flooring for Renovation2: "+customerPreferenceRenovation2AsText);
System.out.println("Your Expected Budget for Renovation2: "+customerBudgetRenovation2);
System.out.println("Our Actual Budget For Painting for Renovation2: "+total_cost_painting);
System.out.println("Our Actual Budget For Flooring for Renovation2: "+calculateTotalFlooringCostBasedOnCustomerPreference(customerPreferenceRenovation2,total_area_carpeting));
System.out.println("For Renovation 3 : Please enter the flooring preference as above and also the total budget:");
customerPreferenceRenovation3 = sc.nextInt();
customerBudgetRenovation3 = sc.nextDouble();
String customerPreferenceRenovation3AsText = displayCustomerFlooringPrefAsText(customerPreferenceRenovation3);
System.out.println("Your have chosen for flooring for Renovation3: "+customerPreferenceRenovation3AsText);
System.out.println("Your Expected Budget for Renovation3: "+customerBudgetRenovation3);
System.out.println("Our Actual Budget For Painting for Renovation3: "+total_cost_painting);
System.out.println("Our Actual Budget For Flooring for Renovation3: "+calculateTotalFlooringCostBasedOnCustomerPreference(customerPreferenceRenovation3,total_area_carpeting));
}
public static double calculateRoomArea()
{
return 2*r_length * r_height + 2 * r_height * r_width + r_length * r_width;
}
public static double calculateDoorArea(double width,double height)
{
return height*width;
}
public static double calculateWindowArea(double width,double height)
{
return height*width;
}
public static double calculateBookShelfArea(double width,double height)
{
return height*width;
}
public static double calculateBookShelfFloorArea(double width,double depth)
{
return depth*width;
}
public static double calculateRoomFloorArea()
{
return r_length*r_width;
}
public static double calculatTotalPaintingCost(double totalAreaPainting)
{
return totalAreaPainting*paintingCostPerSqFt;
}
public static double calculateTotalFlooringCostBasedOnCustomerPreference(int customerFlooringPreference, double totalAreaCarpeting)
{
double calculatedFlooringCost;
switch(customerFlooringPreference)
{
case 1:
calculatedFlooringCost = calculateTotalCeramicTileFlooringCost(totalAreaCarpeting); //Cost=4$/Sq.ft
break;
case 2:
calculatedFlooringCost = calculateTotalHardwoodFlooringCost(totalAreaCarpeting); //Cost=3$/Sq.ft
break;
case 3:
calculatedFlooringCost = calculateTotalCarpetFlooringCost(totalAreaCarpeting); //Cost=2$/Sq.ft
break;
case 4:
calculatedFlooringCost = calculateTotalLinoleumTileFlooringCost(totalAreaCarpeting); //The least expensive one Cost=1$/Sq.ft
break;
default:
calculatedFlooringCost = calculateTotalCeramicTileFlooringCost(totalAreaCarpeting); //The most expensive one Cost=4$/Sq.ft
}
return calculatedFlooringCost;
}
public static double calculateTotalCeramicTileFlooringCost(double totalAreaCarpeting)
{
return totalAreaCarpeting*flooringWithCeramicTileCost;
}
public static double calculateTotalHardwoodFlooringCost(double totalAreaCarpeting)
{
return totalAreaCarpeting*flooringWithHardwoodCost;
}
public static double calculateTotalCarpetFlooringCost(double totalAreaCarpeting)
{
return totalAreaCarpeting*flooringWithCarpetCost;
}
public static double calculateTotalLinoleumTileFlooringCost(double totalAreaCarpeting)
{
return totalAreaCarpeting*flooringWithLinoleumTileCost;
}
public static String displayCustomerFlooringPrefAsText(int flooringPrefNumber)
{
String flooringPreference ="Anything is fine";
switch(flooringPrefNumber)
{
case 1:
flooringPreference ="Ceramic Tile";
break;
case 2:
flooringPreference ="Hardwood";
break;
case 3:
flooringPreference ="Carpet";
break;
case 4:
flooringPreference ="Linoleum tile";
break;
default:
flooringPreference ="Anything is fine";
}
return flooringPreference;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.