Question

In: Computer Science

only the Java programInstructions: This project has three parts. Remember to make a copy of this...

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:

  • The length of the room cannot be less than 5 feet
  • The width of the room cannot be less than 5 feet
  • The user's menu selection for the amount of shade should be 1, 2, or 3.

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?

  1. Little Shade
  2. Moderate Shade
  3. Abundant Shade

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?

  1. Little Shade
  2. Moderate Shade
  3. Abundant Shade

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

Solutions

Expert Solution

***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());
    }
}

Related Solutions

THE QUESTION IS OF JAVA LANGUAGE. ANSWER IS REQUIRED IN THREE PARTS (THREE JAVA FILES). PLEASE...
THE QUESTION IS OF JAVA LANGUAGE. ANSWER IS REQUIRED IN THREE PARTS (THREE JAVA FILES). PLEASE DIFFERENTIATE FILES SO I CAN UNDERSTAND BETTER. NOTE - Submission in parts. Parts required - Dog Class Code, Dog Manager Class Code and the main code. Please differentiate all three in the answer. This Assignment is designed to take you through the process of creating basic classes, aggregation and manipulating arrays of objects. Scenario: A dog shelter would like a simple system to keep...
JAVA PROGRAMMING project 1: Businesses want phone numbers that are easy to remember, and one that...
JAVA PROGRAMMING project 1: Businesses want phone numbers that are easy to remember, and one that can be tied to a phone number are even better. Given the “standard international keypad”, write anaysis and design to determine the phone number based on a user-supplied 7-letter phrase. 1 2 ABC 3 DEF 4 GHI 5 JKL 6 MNO 7 PQRS 8 TUV 9 WXYZ * 0 # Test cases: ● BadDogs ● GoodCat ● Glasses ● EatGood ------------------------------------------------------------------------------------------------------------------------ I ONLY NEED...
parts and function of sarcomere **easy to remember
parts and function of sarcomere **easy to remember
(In java) Return a copy of the string with only its first character capitalized. You may...
(In java) Return a copy of the string with only its first character capitalized. You may find the Character.toUpperCase(char c) method helpful NOTE: Each beginning letter of each word should be capitalized. For example, if the user were to input: "United States of America " --> output should be "United States of America" NOT "United states of america" -------------------------------------- (This code is given) public class Class1 { public static String capitalize(String str) {     //add code here } }
Write a Java class called Employee (Parts of the code is given below), which has three...
Write a Java class called Employee (Parts of the code is given below), which has three private fields firstName (String), lastName (String) and yearsEmployed (double). Implement accessor/mutator methods for the private fields and toString() method, that returns a String representation, which contains employee name and years she was employed. public class Employee { private String firstName; ... } Write a client program called EmployeeClient that creates an instance of Employee class, sets values for the fields (name: John Doe, yearsEmployed:...
Java Language Only Use Java FX In this project we will build a BMI calculator. BMI...
Java Language Only Use Java FX In this project we will build a BMI calculator. BMI is calculated using the following formulas: Measurement Units Formula and Calculation Kilograms and meters (or centimetres) Formula: weight (kg) / [height (m)]2 The formula for BMI is weight in kilograms divided by height in meters squared. If height has been measured in centimetres, divide by 100 to convert this to meters. Pounds and inches Formula: 703 x weight (lbs) / [height (in)]2 When using...
(JAVA) Create three classes, Vehicle, Truck, and Person. The Vehicle class has a make and model,...
(JAVA) Create three classes, Vehicle, Truck, and Person. The Vehicle class has a make and model, test emissions per mile, and a driver/owner (= Person object). (Each vehicle can only have one driver/owner.) The class Truck is a derived class from the Vehicle class and has additional properties load capacity in tons (type double since it can contain a fractional part) and a towing capacity in pounds (type int). Be sure that your classes have appropriate constructors, accessors, mutators, equals(),...
[JAVA] Please make sure there are FIVE (5) different source codes. Do not copy your answers...
[JAVA] Please make sure there are FIVE (5) different source codes. Do not copy your answers or someone’s else answers from different Cheggs. I did not post this question to see the same answers. All information that was given is included. Thank you. I will upvote if you do it properly. Task 1: Add three methods: union, intersection, and difference to the interface BagInterface for the ADT bag. Task 2: Implement the three methods, union, intersection, and difference, for the...
In JAVA, What is the difference between a shallow copy and a deep copy? Include a...
In JAVA, What is the difference between a shallow copy and a deep copy? Include a simple illustration of the difference.
3 Food and Beverage The food industry has many acronyms that make it easier to remember...
3 Food and Beverage The food industry has many acronyms that make it easier to remember food safety terms and actions to control foodborne illness. Managers must know what safety precautions are necessary. Food, Acidity, Temperature, Time, Oxygen, and Moisture is often referred to with the acronym FATTOM. Read the scenario and respond to the checklist item. Scenario: You are catering a wedding buffet in August outside on a venue’s terrace for a wedding reception for 200 people that begins...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT