Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help writing this program in JAVA, this is an introductory java course, so if possible, keep it as basic/simple as possible while still

I need help writing this program in JAVA, this is an introductory java course, so if possible, keep it as basic/simple as possible while still following the instructions. The output should look like the sample execution at the end of the problem.

Design a program that will simulate how theater seats may fill as people walk into the theater. The program should maximize the distance between each person by trying to find a seat in the middle of the longest sequence of unoccupied seats.

For example, consider the situation where ten seats are empty. _ _ _ _ _ _ _ _ _ _

The first person will occupy a middle position: _ _ _ _ _ X _ _ _ _

The next person will be in the middle of the empty area at the left (left has more seats). _ _ X _ _ X _ _ _ _

The next person will be in the section to the right: _ _ X _ _ X _ _ X _

The rest of the diagram should fill in as follows:

_ X X _ _ X _ _ X _ _ X X _ X X _ _ X _ _ X X _ X X _ X X _ X X X _ X X _ X X _ X X X X X X _ X X _ X X X X X X X X X _ X X X X X X X X X X

Write a program that asks the user for the number of seats and then prints out diagrams (one diagram per line) in the format give above each time a new person occupies a seat. In the above example, you would print a total of 11 diagrams (one per line), the empty diagram and then 10 additional diagrams.

HINT: Use an array of booleans to solve this problem. If a person is occupying a seat, that position should be true.

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

MySQL/PHP Database Applications

Authors: Jay Greenspan, Brad Bulger

1st Edition

978-0764535376

More Books

Students also viewed these Databases questions