Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Programming Exercise House Renovation(java programing) Your java program must

ID: 3870800 • Letter: 1

Question

1.       Programming Exercise House Renovation(java programing)

Your java program must work for any valid number of feet including fractions and for any valid cost per square foot. Each run of your program will produce costs for one renovation of painting and carpeting for one room.

You will input ALL values from the console (not defined in program). This will be the length, width and highth of the room. Then the length, highth for door and two windows and the length, width and highth of the bookcase. Finally the cost per square foot for the paint and carpet.

You will figure out the number of square feet of wall space that will need painting and the number of square feet of floor space that will need carpeting. You will need to figure the square feet for each wall (e.g., Lab 02) and then from the total subtract the door, window and bookshelf square feet as each is entered to figure wall space that needs painting.   For the carpet since the bookshelf is built in the middle of a wall you need to subtract its width times length to reduce the floor square feet.

When you have completed this project run your program for each of the house renovation projects listed below. Save the output after each run to turn in with this assignment. Output file is the Java program and then each of the runs (copy them into the same .txt file).

You will output the total number of wall and total floor square feet after the subtraction and then output the cost of the painting and carpet.

First renovation project

Room is 12 feet long, 12 feet wide, and 12 feet high

Door is 2 feet wide by 10 feet high

Window 1 is 3 feet wide by 5 feet high

Window 2 is 3 feet wide by 5 feet high

Bookshelf is 8 feet long by 10 feet high by 2 feet deep

Cost per square foot for painting is $1.00

Cost per square foot for carpeting is $2.00

Second renovation project

Room is 24 feet long, 12 feet wide, and 8 feet high

Door is 2 feet wide by 6 feet high

Window 1 is 3 feet wide by 5 feet high

Window 2 is 8 feet wide by 5 feet high

Bookshelf is 8 feet long by 6 feet high by 3 feet deep

Cost per square foot for painting is $1.57

Cost per square foot for carpeting is $2.89

Third renovation project

Room is 12.75 feet long, 11.25 feet wide, and 12 feet high

Door is 1.95 feet wide by 10 feet high

Window 1 is 2.5 feet wide by 5 feet high

Window 2 is 6.8 feet wide by 7.2 feet high

Bookshelf is 8 feet long by 6 feet high by 3 feet deep

Cost per square foot for painting is $0.95

Cost per square foot for carpeting is $1.25

.

Explanation / Answer

import java.io.*;
import java.util.*;


public class DemoRoom {

   public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter Room length, width and height :");
        double r_length = sc.nextDouble();
        double r_width = sc.nextDouble();
        double r_height = sc.nextDouble();
        System.out.println("Enter Door width, height :");
        double d_width = sc.nextDouble();
        double d_height = sc.nextDouble();
        System.out.println("Enter Window1 width, height :");
        double w1_width = sc.nextDouble();
        double w1_height = sc.nextDouble();
        System.out.println("Enter Window2 width, height :");
        double w2_width = sc.nextDouble();
        double w2_height = sc.nextDouble();
        System.out.println("Enter bookself width, height,depth :");
        double b_width = sc.nextDouble();
        double b_height = sc.nextDouble();
        double b_depth = sc.nextDouble();
        System.out.println("Enter cost per square foot painting :");
        double ct_painting = sc.nextDouble();
        System.out.println("Enter cost per square foot carpeting :");
        double ct_carpeting = sc.nextDouble();

        double r_area = 2 * r_length * r_height + 2 * r_height * r_width
                     + r_length * r_width;
        double w1_area = w1_width * w1_height;
        double w2_area = w2_width * w2_height;
        double d_area = d_height * d_width;
        double b_area = b_height * b_width;
        double b_floor_area = b_depth * b_width;
        double r_floor_area = r_length * r_width;

        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 = total_area_painting * ct_painting;
        double total_cost_carpeting = total_area_carpeting * ct_carpeting;
        System.out.println(" Room is " + r_length + " feet long " + r_width + " feet wide and " + r_height + " feet high. ");
        System.out.println("Door is " + d_width + " feet high by " + d_height + " feet high. ");
        System.out.println("Window 1 is " + w1_width + " feet wide by " + w1_height + " feet high. ");
        System.out.println("Window 2 is " + w2_width + " feet wide by " + w2_height + " feet high. ");
        System.out.println("Bookshelf is " + b_width + " feet long by " + b_height + " feet high by " + b_depth + " feet deep ");
        System.out.println("Cost per square foot for painting is $" + ct_painting + " ");
        System.out.println("Cost per square foot for carpeting is $" + ct_carpeting + " ");
        System.out.println("Total area for painting is " + total_area_painting + " ");
        System.out.println("Total area for for carpeting is " + total_area_carpeting + " ");
        System.out.println("Total cost for painting is $" + total_cost_painting + " ");
        System.out.println("Total cost for for carpeting is $" + total_cost_carpeting + " ");
        try {
            FileWriter fw = new FileWriter("output.txt",true);
            fw.write(" Room is " + r_length + " feet long " + r_width + " feet wide and " + r_height + " feet high. ");
            fw.write("Door is " + d_width + " feet high by " + d_height + " feet high. ");
            fw.write("Window 1 is " + w1_width + " feet wide by " + w1_height + " feet high. ");
            fw.write("Window 2 is " + w2_width + " feet wide by " + w2_height + " feet high. ");
            fw.write("Bookshelf is " + b_width + " feet long by " + b_height + " feet high by " + b_depth + " feet deep ");
            fw.write("Cost per square foot for painting is $" + ct_painting + " ");
            fw.write("Cost per square foot for carpeting is $" + ct_carpeting + " ");
            fw.write("Total area for painting is " + total_area_painting + " ");
            fw.write("Total area for for carpeting is " + total_area_carpeting + " ");
            fw.write("Total cost for painting is $" + total_cost_painting + " ");
            fw.write("Total cost for for carpeting is $" + total_cost_carpeting + " ");
            fw.close();
       }
       catch (Exception e) {
            e.printStackTrace();
       }

   }
}