In: Computer Science
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 in Java 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). Should not be less than 5
Step 2:
Ask the user to enter the width of their room (in feet). Should not be less than 5
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:
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 (Square Feet) |
Air Conditioner Capacity (in BTUs per Hour) |
Under 250 |
5,500 |
From 250 to 500 |
10,000 |
Over 500 to Under 1000 |
17,500 |
1000 or Greater |
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.
First, move any named constants from inside of your main method to above the main method and make them static by adding the “static” keyword in front of them. For example, “static final double TAX_RATE = .075;”. By doing this, all of the static methods you will create below will have access to your named constants so that you do not need to declare them locally in each method.
In addition to the main method, your code must include the following static methods:
Method 1 - displayTitle
A void method that displays the title
Method 2 – calculateArea
A method that accepts the length and width of a room as arguments, and calculates and returns the area of the room
Method 3 – translateShadeChoiceToString
A method that accepts an integer value (1, 2, or 3) that denotes the amount of shade. The method should return the appropriate String representation of the shade. For example, if the method is passed an integer value of 1, it should return a String with a value of “Little”.
Method 4 - calculateBTUsPerHour
A method that accepts the area of a room and the amount of shade a room gets and returns the BTUs per Hour that are needed to adequately cool that room.
Method 5 - displayRoomInformation
A void method that prints out the information for a single room. The output should look exactly the same as the output for Project 2. The method should accept only the arguments necessary to print out the information.
At the end of the output, in the main method, the program should display the number of rooms that have been entered.
Sample Input and Output (user input is in bold) - The output of your program should match the formatting and spacing exactly as shown
Please enter the name of the room: Guest
Bedroom
Please enter the length of the room (in feet):
15.5
Please enter the width of the room (in feet):
10
What is the amount of shade that this room receives?
Please select from the options above: 3
Air Conditioning Window Unit Cooling Capacity
Room Name: Guest Bedroom
Room Area (in square feet): 155.0
=======================
JAVA PROGRAM
=======================
////////////////AirConditioningCapacity.JAVA/////////////////////////
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);
}
}
==============================
OUTPUT
==============================
Please enter the name of the room:
Guest Bedroom
Please enter the length of the room (in feet):
15.5
Please enter the width of the room (in feet):
10
What is the amount of shade that this room receives?
Little Shade
Moderate Shade
Abundant Shade
Please select from the options above:
1
Air Conditioning Window Unit Cooling Capacity
Room Name: Guest Bedroom
Room Area (in square feet): 155.0
Room Shade: Little Shade
Capacity of the air conditioning unit (in BTU Per Hour): 6325.0
Press Y to enter another room or any other key to exit:
Y
Please enter the name of the room:
Dining Room
Please enter the length of the room (in feet):
25
Please enter the width of the room (in feet):
18.5
What is the amount of shade that this room receives?
Little Shade
Moderate Shade
Abundant Shade
Please select from the options above:
3
Air Conditioning Window Unit Cooling Capacity
Room Name: Dining Room
Room Area (in square feet): 462.5
Room Shade: Abundant Shade
Capacity of the air conditioning unit (in BTU Per Hour): 9000.0
Press Y to enter another room or any other key to exit:
Y
Please enter the name of the room:
Kitchen
Please enter the length of the room (in feet):
30
Please enter the width of the room (in feet):
12
What is the amount of shade that this room receives?
Little Shade
Moderate Shade
Abundant Shade
Please select from the options above:
2
Air Conditioning Window Unit Cooling Capacity
Room Name: Kitchen
Room Area (in square feet): 360.0
Room Shade: Moderate Shade
Capacity of the air conditioning unit (in BTU Per Hour):
10000.0
Press Y to enter another room or any other key to exit:
n
Total number of rooms entered: 3