Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

FOCUS TOPICS Arrays: storing multiple values of the same type Loops TASK You are working for a company that runs virtualized computing environments for rent.

image text in transcribed
image text in transcribed
image text in transcribed
FOCUS TOPICS Arrays: storing multiple values of the same type Loops TASK You are working for a company that runs virtualized computing environments for rent. You have been asked to write a program that turns virtual servers on and off. At this point, you are writing only the user interaction code(i.e., you aren't yet actually turning anything on or off. The program should do the following Create and manage a set of data structures for keeping track of the status of each server Allow the user to select servers to turn on Print the status of the servers, and compute simple quality statistics: the total number of servers that are running, the average number of servers that are running, and the quality grade for the server farm based on the percentage of running servers. The grade is A for 80% or more, B for 60% or more and less than 80%, and C for less than 60% INSTRUCTIONS 1. Declare a named integer constant MAXSERVERS with a value of 10. Base all your code on this constant, do not use the literal 10 anywhere Prompt the user to enter the number of servers in the farm, from 1 to MAXSERVERS. See Sample output for the format. Check that the user entered a valid number. If the user input is out of range (below 1 or above MAXSERVERS), prompt the user for correct input until a valid number is entered. 2. 3. THINK: loop. What type of loop would work best for this? A while loop or a for loop? o Think about this for a minute. This requires repeated input, so you'll need a 4. Declare a boolean array called isServerRunning. o Use the input server count as the array size. o For any index in the array, a value of false will mean the server is stopped, and true will mean the server is running. Initialize all array elements to false to indicate that all servers are stopped. o THINK: Think about this for a minute. This requires repeated input, so you'll need a loop. What type of loop would work best for this? A while loop or a for loop? S. Allow the user to "turn on" servers by entering server numbers repeatedly. indicate when they are finished turning on servers Allow the user to o Prompt the user to enter values, or-1 to stop. (See the sample output for the format.) THINK: Think about this for a minute. This requires repeated input, so you'll need a loop. What type of loop would work best for this? A while loop or a for loop? o Within the loop: - Use nextint() to read the index number of the server to be turned on. -Exit the loop if the user has entered the loop exit condition(-1) If the value is a valid server value, set the boolean value in the isServerRunning array to true, and prompt again for further input -For any value that is not a valid server ID or the loop exit condition, print an error message, and prompt again for further input 6. After the user is finished with the input, print the status of servers to screen. Use 'o' for a running server and 'x'for a stopped server. Separate the symbols by a space and print them all on one line. (See the sample output for formatting.) Compute the total number of servers running, and print it. 7. 8. Compute percentage number of servers running, and print it. Be sure to capture the full 9, Compute the server farm quality grade. The grade is A for 80% or more, B for 60% or more and 10. Make sure that your output matches the sample output in wording, punctuation, and spacing. floating-point value of the result. less than 80%, and C for less than 60%. Print the grade to screen. SAMPLE OUTPUT Enter the number of servers (1-10): Not a valid input Try again Enter the number of serves (1-10) Not a valid input Try again Enter the nuter of @rver (1-10); Enter a server to turn on (1-1) or -1 to quit: Enter a server to turn on (1-1) or -1 to quit: Humber of server running: 1 percentagef servers running: 1.0 Farm quality zating: A BUILD SUCCESSFUL (total time: 1 minute 28 seconds) Enter the number of ervers (1-10): 7 Enter a server to turn on (1-7) or -i to quit: Enter a server to turn on (1-7) or -1 to quit: Enter a server to turn on (1-7) or -1 to quit: Enter a server to turn on (1-7) or -1 to quit: 7 Enter a erver to turn on (1-7) -1 t quit: 13 Error in input Try again Enter a server to turn on (1-7) or -1 to quit: Number of servers running: 4 Percentage of server running: 0.5714285714285714 Farm quality rating: C BUILD SUCCESSFUL (total time: 24 seconds) un Enter the number of servers (1-10): Enter a server to turn on (1-3) or -1 to quit: Enter a server to turn on (1-3) or -1 to quit: Entez a server to turn on (1-3) or 1 to quit: Enter a server to turn on (1-3) or -1 to quit: Enter a server to turn on (1-3) oz -l to quit: Enter a server to turn on (1-3) -1 to quit: Number of servers running: 3 Percentage of servezs running: 1.0 Farm quality rating: a BUILD SUCCESSEUL (total time: 12 seconds)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions

Question

5. Prepare for the role of interviewee

Answered: 1 week ago

Question

6. Secure job interviews and manage them with confidence

Answered: 1 week ago