Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Sample Runs (user input in color) Run 1 (invalid input type): How many stalls in the bathroom? 13.6 Invalid number of stalls 13.6 Run

JAVA

image text in transcribed

Sample Runs (user input in color)

Run 1 (invalid input type):

How many stalls in the bathroom? 13.6 Invalid number of stalls 13.6

Run 2 (invalid number of stalls):

How many stalls in the bathroom? 0 Invalid number of stalls 0

Run 3 (invalid number of stalls):

How many stalls in the bathroom? -3 Invalid number of stalls -3

Run 4 (odd number of stalls):

How many stalls in the bathroom? 11 _ _ _ _ _ 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 X X X X X X X X X X X X X X X X X

Run 5 (even number of stalls):

How many stalls in the bathroom? 8 _ _ _ 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

It is a well-researched fact that men in a restroom generally prefer to maximize their distance from already occupied stalls, by occupying the middle of the longest sequence of unoccupied places. For example, consider the situation where ten stalls are empty. The first visitor will occupy a middle position: The next visitor will be in the middle of the empty area at the left. Write a program that reads the number of stalls and then prints out diagrams in the format given above when the stalls become filled, one at a time. Hint Use an array of boolean values to indicate whether a stall is occupied. Part 1: Problem-Solving Phase (40 polnts) Using the Design Reclpe, write each of the following for thls problem: Contract Purpose Statement Examples, making sure to Include counter-examples Algorlthnm Make sure to test your algorlthm by hand wlth the examples to verlfy It before continulng to Part 2. Part 2: Implementatlon Phase (60 polnts) Using Ecllpse, wrlte the Java program for the algorlthm formulated In Part 1, and test your program wlth the examples from Part 1. Make sure to Incorporate your Contract, Purpose Statement and Examples as one or more comment blocks, and your Algorlthm as llne comments In your Java source code

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

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago