Question

In: Computer Science

You are writing a program for an architectural firm that needs to enter the areas of...

You are writing a program for an architectural firm that needs to enter the areas of all the rooms in a building project they’re working on. Some rooms are square, some are round, and some are rectangular. Each room in the building has an ID number to help prevent adding the same room more than once. The program needs to prompt the user for the room ID number, the shape of the room, and the dimensions needed to calculate the area. It should store the ID number and the calculated area in sq. ft. (rounded to the nearest foot) of each room in a single integer ArrayList in the order: ID, area, ID, area, ... If the room ID has already been entered, it should let the user know and prompt for another. The program should continue running until the user chooses to close the program. It should also allow the user to view a list of the current rooms’IDs and areas, the total area, and the average room area. The program will need at least the following methods. The only global variable should be a Scanner object.•public static void main(String[] args)controls the flow of the program and manages the integer ArrayList.It will present the user with the choice to enter a new room, view room statistics, or exit the program. If an invalid choice is made, it should just repeat the menu of choices.•public static void getRoomId(ArrayList<Integer> data)asks the user for the ID of the room they’re reporting on, checks to make sure that ID has not already been entered, and adds the ID to the ArrayList. It should bulletproof input and allow the user to keep trying until a valid, unique ID is entered.•public static int getRoomShape() gets the room shape selection from the user by presenting a numbered menu (such as 1 –square, 2 –round, 3 –rectangular.) It should bulletproof input and allow the user to keep trying until a valid choice is entered.•public static int calcArea(int roomShape)calculates the room area based on the shape of the room selected, prompting the user for the data needed to do the calculation (width for square, diameter for round, length and widthrectangular.)•public static void displayStats(ArrayList<Integer> data) reads all the data stored in the ArrayList, prints out the entire list of room IDs and areas, followed by the total area of all the rooms added together and the average room area based on the number of rooms currently entered.You are welcome to add more methods if necessary, but you have to have the above methods. The program should be error free and user friendly. Proper indentation and spacing is expected, but you do not have to add JavaDoc comments.

Solutions

Expert Solution

CODE -

import java.util.ArrayList;

import java.util.Scanner;

public class rooms {

    // Create scanner object globally

    static Scanner keyboard = new Scanner(System.in);

    

    // Function to get room ID from the user

    public static void getRoomId(ArrayList<Integer> data)

    {

        int roomId;

        // Take room ID as input

        System.out.print("Enter Room ID: ");

        roomId = keyboard.nextInt();

        // Prompt user for a unique room ID and take room ID as input until user enters an unique room ID

        while (data.contains(roomId))

        {

            System.out.println("\nRoom already added! Try again\n");

            System.out.print("Enter Room ID: ");

            roomId = keyboard.nextInt();

        }

        // Add room ID to the ArrayList

        data.add(roomId);

    }

    // // Function to get room shape from the user

    public static int getRoomShape()

    {

        int roomShape;

        // Display the choice of shapes available

        System.out.println("Select the shape of the room");

        System.out.println("1. Square");

        System.out.println("2. Round");

        System.out.println("3. Rectangular");

        // Take the user's choice of shape as input

        System.out.print("\nEnter your choice: ");

        roomShape = keyboard.nextInt();

        // Take input from the user until user enters an available shape as his/her choice.

        while(roomShape<1 || roomShape>3)

        {

            System.out.println("\nNo such shape available! Select from the avilable choices.\n");

            System.out.print("Enter your choice: ");

            roomShape = keyboard.nextInt();

        }

        // Return the shape

        return roomShape;

    }

    // // Function to get dimensions of the room as input based on the room shape and calculate the area of the room

    public static int calcArea(int roomShape)

    {

        int area = 0;

        if (roomShape == 1)

        {

            // Take width of the room as input if shape of the room is square

            System.out.print("Enter the width of the room: ");

            float width = keyboard.nextFloat();

            // Calculate area of the room

            area = Math.round(width * width);

        }

        else if (roomShape == 2)

        {

            // Take diameter of the room as input if shape of the room is round

            System.out.print("Enter the diameter of the room: ");

            float diameter = keyboard.nextFloat();

            // Calculate area of the room

            area = (int)Math.round(Math.PI * (diameter/2) * (diameter/2));

        }

        else if(roomShape == 3)

        {

            // Take length and width of the room as input if shape of the room is rectangular

            System.out.print("Enter the length of the room: ");

            float length = keyboard.nextFloat();

            System.out.print("Enter the width of the room: ");

            float width = keyboard.nextFloat();

            // Calculate area of the room

            area = Math.round(length * width);

        }

        // Return the area of the room

        return area;

    }

    public static void displayStats(ArrayList<Integer> data)

    {

        int totalArea = 0;

        // Display ID and area of all the room and also calculate the total area

        for (int i=0; i<data.size(); i+=2)

        {

            System.out.println("Room ID:   " + data.get(i));

            System.out.println("Room area: " + data.get(i+1) + "\n");

            totalArea += data.get(i+1);

        }

        // Calculate average area of all the rooms

        int avgArea = Math.round(totalArea / (data.size()/2));

        // Display total area of all the rooms and the average area

        System.out.println("Total area of all the rooms: " + totalArea);

        System.out.println("Average room area: " + avgArea);

    }

    public static void main(String[] args)

    {

        int choice;

        ArrayList<Integer> data = new ArrayList<>();

        int roomShape, area;

        // Loop to run until user chooses to quit

        while(true)

        {

            // Display menu

            System.out.println("\nBuilding Project Menu");

            System.out.println("1. Enter a new Room");

            System.out.println("2. View Room Statistics");

            System.out.println("3. Quit the Program");

            // Take choice as input from user

            System.out.print("\nEnter your choice: ");

            choice = keyboard.nextInt();

            // Perform action based on user's choice

            if(choice == 1)

            {

                getRoomId(data);

                roomShape = getRoomShape();

                area = calcArea(roomShape);

                data.add(area);

            }

            else if(choice == 2)

                displayStats(data);

            else if(choice == 3)

            {

                System.out.println("\nThank You for using our Program\n");

                break;

            }

            else

                System.out.println("\nInvalid Choice!\n");

        }

    }

}

SCREENSHOTS -

CODE -

OUTPUT -

If you have any doubt regarding the solution, then do comment.
Do upvote.


Related Solutions

C++ Code Writing prompt: Grade Calculation: Write a program that asks the user to enter in...
C++ Code Writing prompt: Grade Calculation: Write a program that asks the user to enter in a number greater than or equal to zero and less than or equal to 100. If they do not you should alert them and end the program. Next, determine the letter grade associated with the number. For example, A is any grade between 90 and 100. Report the letter grade to the user.
imagine that you are the human resource manager of a small architectural firm. you learn that...
imagine that you are the human resource manager of a small architectural firm. you learn that the monthly premiums for the company existing health insurance policy will rise by 15% next year.what can you suggest to help your company manage this rising cost?
An architectural firm of eight employees, each with a networked desktop computer, wants you to develop...
An architectural firm of eight employees, each with a networked desktop computer, wants you to develop a security policy for the company. Management has emphasized the ease of use is paramount, and little time is available for training. What level of security should policy reflect?
You are writing a billing program that adds up the items a user enters. Your program...
You are writing a billing program that adds up the items a user enters. Your program should use a loop and prompt the user for the item number for each item in inventory to add to the bill. (You can ask the user for the number of items you will enter and use a counter controlled loop or a sentinel controlled loop that has a stop number. Either way is fine.) Here is the table of items in inventory: Item...
in python You will be writing a program that can be used to sum up and...
in python You will be writing a program that can be used to sum up and report lab scores. Your program must allow a user to enter points values for the four parts of the problem solving process (0-5 points for each step), the code (0-20 points), and 3 partner ratings (0-10) points each. It should sum the points for each problem-solving step, the code, and the average of the three partner ratings and print out a string reporting the...
You are off to shopping and need a program that allows you to enter the names...
You are off to shopping and need a program that allows you to enter the names of items, their price and quantities. Here is what a sample run should look like (with the keyboard input shown in italics) ... Enter item information ("exit" to exit) item 1: chips price: 3.5 quantity: 2 Enter item information ("exit" to exit) item 2: red wine price : 15.0 quantity : 1 Enter item information ("exit" to exit) item 3 : steaks price :...
Income at the architectural firm Spraggins and Yunes for the period February to July was as...
Income at the architectural firm Spraggins and Yunes for the period February to July was as follows:                                                           Month February March April May June July Income​ ($000's) 75 71.5 66.4 72.3 73.5 74 Assume that the initial forecast for February is 70 ​(in $​ thousands) and the initial trend adjustment is 0. The smoothing constants selected are alpha (α) ​= 0.1 and beta (β) ​= 0.3 1) Using​ trend-adjusted exponential​ smoothing, the forecast for the architectural​ firm's August income is...
Income at the architectural firm Spraggins and Yunes for the period February to July was as​...
Income at the architectural firm Spraggins and Yunes for the period February to July was as​ follows:                                                                                                                                 Month February March April May June July Income​ ($000's) 90.090.0 91.591.5 96.096.0 85.485.4 92.292.2 96.096.0 Assume that the initial forecast for February is 85.085.0 ​(in $​ thousands) and the initial trend adjustment is 0. The smoothing constants selected are alphaα ​= 0.10.1 and betaβ ​= 0.20.2. Using​ trend-adjusted exponential​ smoothing, the forecast for the architectural​ firm's August income is nothing thousand dollars...
In python make a simple code. You are writing a code for a program that converts...
In python make a simple code. You are writing a code for a program that converts Celsius and Fahrenheit degrees together. The program should first ask the user in which unit they are entering the temperature degree (c or C for Celcius, and f or F for Fahrenheit). Then it should ask for the temperature and call the proper function to do the conversion and display the result in another unit. It should display the result with a proper message....
You will be writing a C program to test the data sharing ability of a thread...
You will be writing a C program to test the data sharing ability of a thread and process. Your C program will do the following: 1. Your parent program will have three variables: int x,y,z; which to be initialized as 10, 20, and 0, respectively. 2. parent creating child: parent will create a child by fork() and the child will perform z = x+y (i.e., add x and y and store the results in z). parent will wait for child...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT