Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Read all the instructions carefully and write this program in java. I am a very begineer in java. Please donot use break statements in this

Read all the instructions carefully and write this program in java. I am a very begineer in java. Please donot use break statements in this program and please add comments so i can understand your code

This problem is based on chapter 10 information. You have N mailboxes in a row. I want you to make this number entered by the user. These mailboxes will be represented in an array. Each mailbox has only two states open or closed. So make this an array of Boolean, true = closed, false = open. Start with all mailboxes closed. In a loop, begin with mailbox #2 (remember this is index 1 in the list) and open it and every 2nd mailbox. Now starting with mailbox 3, and continuing every 3rd mailbox we will open it if it is closed and close it if it is opened. Go to the fourth and reverse the status of every fourth mailbox the same way. Continue opening and closing mailboxes every 5th, every 6th, etc until we get to where we are starting at mailbox N (the last one). Report all the mailboxes that are closed after we finish our procedure. Do not report the open ones. You should see a recognizable pattern with the few that remain closed. (I should be able to test any integer value and have it work correctly.)

Sketch it out first to see what should happen.

If user enters 5:

Initial state: closed closed closed closed closed (all closed)

Every 2nd: closed open closed open closed (all divisible by 2 get reversed)

Every 3rd: closed open open open closed (all divisible by 3 get reversed)

Every 4th: closed open open closed closed (all divisible by 4 get reversed)

Every 5th: closed open open closed open (all divisible by 5 get reversed, 1 and 4 are still closed)

Output Example (User input is marked with >>>. Everything else is what you print to the screen.)

This program will close and open mailboxes in a fixed pattern. How many mailboxes would you like to see?

>>> 5

The following mailboxes are still closed at the end of the program: 1 4

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

Proficiency with Microsoft Word, Excel, PowerPoint

Answered: 1 week ago

Question

Experience with SharePoint and/or Microsoft Project desirable

Answered: 1 week ago