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?
Language: C++ The program I have written below needs to allow the user to enter in...
Language: C++ The program I have written below needs to allow the user to enter in their own date, however I currently can only get it to output a default date, 10/10/2018. After the user enters the date it needs to go through the exception checks to make sure it is a valid date. Afterword the user needs to be prompted to change their date. Here is the code: #include <iostream> #include <cmath> #include <fstream> #include <cstring> #include <sstream> #include...
The program you will be writing displays a weekly payroll report. A loop in the program...
The program you will be writing displays a weekly payroll report. A loop in the program should ask the user for the employee's number, last name, worked hours, hourly pay rate, state tax and federal tax rate. After data in entered and the user hits the enter key, the program will calculate gross an net pay, then displays all employee's payroll information, and ask for the next employees' information. if worked hour is more than 40, double pay the hours...
You are on a diet and you are writing a javascript program that determines whether or...
You are on a diet and you are writing a javascript program that determines whether or not you can treat yourself to an ice cream. Your program takes as input: 1. Number of calories you have taken so far that day. 2. Number of calories you are expecting to take later on that day (excluding the potential ice cream) 3. Number of calories you have burnt (or are expecting to burn) with exercise that day. 4. What is your goal...
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?
Program Specifications: You will be writing a Java program called ASCIIRabbit.java that will print the following...
Program Specifications: You will be writing a Java program called ASCIIRabbit.java that will print the following ASCII objects. There should be two blank lines between each shape and your output must match identically. Rabbit In A Hat -------------------- (^\ /^) \ V / (o o) ( (@) ) --------- | | | | | | _______ Rabbit Under A Hat -------------------- _______ | | | | | | --------- /\"/\ () * () ("")_("") Rabbit Wears A Hat ------------------ _______...
The following task does not involve writing program code: instead, you will be writing function signatures...
The following task does not involve writing program code: instead, you will be writing function signatures for hypothetical functions (you will be defining functions in subsequent tasks). For this task, you are presented with several 'hypothetical' functions. These aren't built-in Python functions: they are functions that you will have to define (i.e. implement, write) yourself later. however, you only need to write a signature for each hypothetical function listed here: toThePower(): takes two numbers e.g. x and y , and...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT