In: Computer Science
only the Java programInstructions:
This project has three parts. Remember to make a copy of this project so you can refer to it when completing the other phases.
Review the sample program before starting this project. The sample program does not exactly match the requirements for this project, so some critical thinking will still be required; however, it is a good thing to reference before starting the project.
Project 2 is a continuation of Project 1. Modify the code from Project 1 in the following ways:
Step 1: Add code to prompt the user to enter the name of the room that they are entering information for.
Step 2: Add Input Validation to the code using the following rules:
If the user's input is invalid, the program should display an appropriate error message and prompt the user to re-enter their input. The user should be given an unlimited amount of attempts to enter valid input
Step 3: Add code to have the program ask the user if they would like to enter information about another room after the information for a previous room has been processed and displayed. The user should be able to enter a "y" or "Y" to indicate that they want to enter information about another room. See the Sample Input and Output for how to format this.
Step 4: After the user has indicated that they do not wish to enter information about another room, the program should output the number of rooms that have been entered and then stop executing.
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
Amount of Shade: Abundant
BTUs Per Hour needed: 4,950
Would you like to enter information for another room (Y/N)? Y
Please enter the name of the room:
Kitchen
Please enter the length of the room (in feet):
20
Please enter the width of the room (in feet):
15
What is the amount of shade that this room receives?
Please select from the options above: 2
Air Conditioning Window Unit Cooling Capacity
Room Name: Kitchen
Room Area (in square feet): 300.0
Amount of Shade: Moderate
BTUs Per Hour needed: 10,000
Would you like to enter information for another room (Y/N)? N
The total number of rooms processed was: 2
***Please upvote/thumbsup if you liked the answer***
Screenshot of the Java code:-
Output:-
Java code to copy:-
Note:- As you haven't given the Project 1,I don't know what rooms are already there or if there is any BTU calculation
package RoomProject; import java.text.NumberFormat; public class Room { private String type; private float length; private float width; private String shade; public Room(String type,float length, float width, String shade) { this.type = type; this.length = length; this.width = width; this.shade = shade; } public float getArea(){ return length * width; } public void setType(String type) { this.type = type; } public void setLength(float length) { this.length = length; } public void setWidth(float width) { this.width = width; } public void setShade(String shade) { this.shade = shade; } public int getBTU(){ if (type.equals("Guest Bedroom")) return 4950; else if (type.equals("Kitchen")) return 10000; else return 0; } public String toString() { NumberFormat myFormat = NumberFormat.getInstance(); myFormat.setGroupingUsed(true); return "Air Conditioning Window Unit Cooling Capacity\n" + "Room Name: " + this.type +"\n" + "Room Area(in square feet): " + this.getArea() + "\n" + "Amount of Shade: " + this.shade + "\n" + "BTUs Per Hour needed: " + myFormat.format(this.getBTU()) + ""; } }
package RoomProject; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class RoomDemo { public static void main(String[] args) { String[] shadesList = {"Little","Moderate","Abundant"}; List<Room> rooms = new ArrayList<>(); Room temp; Scanner s = new Scanner(System.in); String type; float length,width; int shade; char more; do { System.out.println("Please enter the name of the room:"); type = s.nextLine(); System.out.println("Please enter the length of the room (in feet):"); length = Float.parseFloat(s.nextLine()); //Length validation while(length < 5) { System.out.println("Please re-enter the correct length of the room"); length = Float.parseFloat(s.nextLine()); } System.out.println("Please enter the width of the room (in feet):"); width = Float.parseFloat(s.nextLine()); //Width validation while(width < 5) { System.out.println("Please re-enter the correct width of the room"); width = Float.parseFloat(s.nextLine()); } System.out.println("What is the amount of shade that this room receives?"); System.out.println("Little Shade"); System.out.println("Moderate Shade"); System.out.println("Abundant Shade"); System.out.println("Please select from the options above:"); shade = Integer.parseInt(s.nextLine()); //Validating option of shade while(shade != 1 || shade != 2 || shade != 3) { System.out.println("Please select the correct option"); shade = Integer.parseInt(s.nextLine()); } temp = new Room(type,length,width,shadesList[shade - 1]); rooms.add(temp); System.out.println(temp); System.out.println("Would you like to enter information for another room (Y/N)?"); more = s.nextLine().charAt(0); } while (more != 'N'); System.out.println("The total number of rooms processed was: " + rooms.size()); } }