A+ Work



(Must be done in BlueJ).

We ask you to write a program that mimics a mailman conducting an experiment in flipping mailboxes. A flip means opening a mailbox if it is closed, and closing a mailbox if it is open. There are 100 mailboxes numbered 1 to 100 that are all initially closed. In the first step, visiting every mailbox (i.e. mailboxes 1, 2, 3, ..., 100), he flips them all. Then in the second step, visiting every second mailbox (i.e. mailboxes 2, 4, 6, ..., 100), he flips them. Then in the third step, visiting every third mailbox (i.e. mailboxes 3, 6, 9, ..., 99), he flips them. In this manner he goes in steps of 4, 5, ..., 10,...,50, and finally 100, wherein he directly goes to the 100th mailbox and flips it. At the end of this process, which mailboxes are open? Hint: Set up an array of Booleans all initialized to false representing closed mailboxes. Then, in steps of 1, 2, 3, …, 100 go through the sequence of mailboxes and toggle them. In the end, print out the mailbox numbers that are open (have the value true).

Create a new project in BlueJ by clicking on the menu option Project > New project. This will create a folder with the project name (see below). All BlueJ project-related files for this project will be stored in this folder. Create new classes by clicking on the [New Class] button. All Java class files that you create (.java files) will be stored in the BlueJ project folder. The project folder will contain other files as well. After completing and testing your assignment, zip the entire BlueJ folder and submit it. Since your Instructor will need all files in the project folder, make sure you zip the entire folder. For this assignment the names of the BlueJ project, Java class files, and the zip file you submit are given below:

BlueJ project: mailbox_puzzle