In some older homes that do not have a central heating and air conditioning system, smaller air conditioning units made to fit inside of a window and cool a single room are used as an alternative way to cool the home. Depending on the size of the room and the amount of shade that the room has, different sizes of air conditioning units must be used in order to be able to properly cool the room. The unit of measure for the amount of cooling that an air conditioner unit can provide is the BTU (British Thermal Unit) per hour. Code a program that will calculate the correct size of air conditioner for a specific room size using the instructions below. Step 1:
In some older homes that do not have a central heating and air conditioning system, smaller air conditioning units made to fit inside of a window and cool a single room are used as an alternative way to cool the home.
Depending on the size of the room and the amount of shade that the room has, different sizes of air conditioning units must be used in order to be able to properly cool the room. The unit of measure for the amount of cooling that an air conditioner unit can provide is the BTU (British Thermal Unit) per hour.
Code a program that will calculate the correct size of air conditioner for a specific room size using the instructions below.
Step 1:
Ask the user to enter the length of their room (in feet).
Step 2:
Ask the user to enter the width of their room (in feet).
Step 3:
Calculate the area (in square feet) of the room by multiplying the length and the width of the room.
For example, if a room is 20 feet wide by 24 feet long, then its area is 20 * 24 = 480 square feet
Step 4:
Display a menu that asks the user how much shade the room gets. The menu should have the following options:
- Little Shade
- Moderate Shade
- Abundant Shade
Step 5:
Determine the capacity of the air conditioning unit that is needed for a moderately shaded room by using the information in the table below.
Room Size (sq. ft) |
AC capacity (BTUs/hr) |
Less than 250 |
5,500 |
250 to 500 |
10,000 |
501 to 1,000 |
17,500 |
Over 1,000 |
24,000 |
If the room has little shade, then the BTU capacity should be increased by 15% since the air conditioning unit must be able to produce extra cooling.
If the room has abundant shade, then the BTU capacity should be decreased by 10% since the air conditioning unit does not need to work as hard to cool a shaded room.
Step 6:
Create a String object in memory to hold the text “Air Conditioning Window Unit Cooling Capacity”. Display that text at the top of the output.
Step 7:
Display the following output:
-
- The area of the room (in square feet)
- The amount of shade that the room gets
- The number of BTUs per Hour that are needed to cool that room (rounded to the nearest whole number)
Write in python please.
import java.util.Scanner;
/**
* Class: AirConditioningCapacity
* File: AirConditioningCapacity.java
* Purpose: To calculate ac unit capacity based on user input
*/
public class AirConditioningCapacity {
//constants for different ac capacity based on room areas
private static final double CAPACITY_FOR_ROOM_UNDER_250 = 5500;
private static final double CAPACITY_FOR_ROOM_250_TO_500 = 10000;
private static final double CAPACITY_FOR_ROOM_OVER_500_UNDER_1000 = 17500;
private static final double CAPACITY_FOR_ROOM_1000_OR_GREATER = 24000;
//constants defined for increase or decrease in capacity based on room shade
private static final double CAPACITY_INCREASE_FOR_LITTLE_SHADE = 0.15; //15%
private static final double CAPACITY_DECREASE_FOR_ABUNDANT_SHADE = 0.10; //10%
//all room shades are defined in array
private static final String[] roomShades = {"Little Shade","Moderate Shade","Abundant Shade"};
//main method starts
public static void main(String[] args){
//scanner instance created
Scanner sc = new Scanner(System.in);
int roomCounter = 0; //this will keep track of number of rooms
//continue to take rooms as long as user wants
do{
roomCounter++; //keep track of number of rooms entered
System.out.println("Please enter the name of the room: ");
String roomName = sc.nextLine(); //read name of room
System.out.println("Please enter the length of the room (in feet): ");
double length = Double.parseDouble(sc.nextLine());//read length
System.out.println("Please enter the width of the room (in feet): ");
double width = Double.parseDouble(sc.nextLine());//read width
System.out.println("What is the amount of shade that this room receives?");
for(String shade: roomShades){//print different room shades
System.out.println(shade);
}
System.out.println("Please select from the options above: ");
int amountOfShade = Integer.parseInt(sc.nextLine());//take data for amount of shade
//translate room shade into String info
String roomShade = translateShadeChoiceToString(amountOfShade);
double area = calculateArea(length, width); //calculate area of the room
double acCapacity = calculateBTUsPerHour(area, amountOfShade);//calculate capacity
displayTitle();//print title
displayRoomInformation(roomName, area);//display room info
//additionally prints room shade
System.out.println("Room Shade: "+roomShade);
//finally prints capacity of the ac unit
System.out.println("Capacity of the air conditioning unit "
+ "(in BTU Per Hour): "+acCapacity);
//checks if user wants to enter another room
System.out.println("\nPress Y to enter another room or any other key to exit: ");
String userChoice = sc.nextLine(); //read user's choice
if(!userChoice.equalsIgnoreCase("Y")){ //if anything other than Y or y is entered
break;//break out of the loop
}
}while(true);
//print room counter
System.out.println("Total number of rooms entered: "+ roomCounter);
}
/**
* display title
*/
public static void displayTitle(){
System.out.println("Air Conditioning Window Unit Cooling Capacity");
}
/**
* calculate area of the room
* @param length
* @param width
* @return
*/
public static double calculateArea(double length,double width){
double area = 0;
if(length > 0 && width > 0){
area = length * width;
}
return area;
}
/**
* convert amountOfShade to Stringequivlent
* using roomShades array
* @param amountOfShade
* @return
*/
public static String translateShadeChoiceToString(int amountOfShade){
String shadeChoice = "Invalid Shade Choice";
//if amount of shade is in range of number of shades
if(amountOfShade >= 0 && amountOfShade <=roomShades.length){
shadeChoice = roomShades[amountOfShade -1]; //take value from array
}
return shadeChoice;
}
/**
* calculate capacity based on room area and amountOfShade
* @param area
* @param amountOfShade
* @return
*/
public static double calculateBTUsPerHour(double area,int amountOfShade){
double capacityInBTUPerHour = 0;
//check for different room sizes
if(area < 250){
capacityInBTUPerHour = CAPACITY_FOR_ROOM_UNDER_250;
}else if(area >=250 && area <= 500){
capacityInBTUPerHour = CAPACITY_FOR_ROOM_250_TO_500;
}else if(area > 500 && area < 1000){
capacityInBTUPerHour = CAPACITY_FOR_ROOM_OVER_500_UNDER_1000;
}else if(area >= 1000){
capacityInBTUPerHour = CAPACITY_FOR_ROOM_1000_OR_GREATER;
}
//check for different room shades
if(amountOfShade ==1){ //for little shade increase by 15%
capacityInBTUPerHour += capacityInBTUPerHour*CAPACITY_INCREASE_FOR_LITTLE_SHADE;
}else if(amountOfShade ==2){ //for moderate shade no change
//no change, keep it as it is
}else if(amountOfShade == 3){//for abundant shade decrease by 10%
capacityInBTUPerHour -= capacityInBTUPerHour*CAPACITY_DECREASE_FOR_ABUNDANT_SHADE;
}
return capacityInBTUPerHour;
}
/**
* display room name and area
* @param roomName
* @param roomArea
*/
public static void displayRoomInformation(String roomName,double roomArea){
System.out.println("Room Name: "+roomName);
System.out.println("Room Area (in square feet): "+roomArea);
}
}
Step by step
Solved in 2 steps