Mailboxes Java
Peter the postman was bored one evening and he decided to experiment with the mailboxes in the mailroom. The mailboxes were numbered from zero to 200 (there were 201 total mailboxes). Initially all boxes were closed. Starting with mailbox #2, he opened the door of every even numbered mailbox. Next, beginning with mailbox #3 and going to every third mailbox, he opened its door if it was closed and closed it if it was open. Then he repeated this procedure with every fourth mailbox starting with mailbox #4; and then every fifth mailbox starting with mailbox #5; continuing in this manner all the way up to the changing every 200th mailbox starting with mailbox #200 (which of course just changes mailbox #200).
Your job is to write a program to determine which mailboxes were closed at the end of the experiment.The program should ask the user for how many mailboxes are in the mailroom, and then perform the desired experiment for that many mailboxes. This will allow us to run the experiment for a small mailroom with only 201 mailboxes, or a large mailroom with thousands of mailboxes.
Notes:
Example execution (user input is 5)
This is an example execution to show you how Mailboxes.java should behave, it is run for only 5 mailboxes
How many mailbox are in the mailroom? 5
When done, here are all the mailboxes that are closed:
Box #0; distance from previous box: 0
Box #1; distance from previous box: 1
Box #4; distance from previous box: 3
Mailboxes.java
import java.util.Arrays;
import java.util.Scanner;
public class Mailboxes {
private static final int OPEN = 1;
private static final int CLOSED = 0;
public static void main(String[]args)
{
Scanner sc = new Scanner(System.in);
System.out.print("How many mailbox are in the mailroom? ");
int nMailbox = Integer.parseInt(sc.nextLine().trim());
int mailboxes[] = new int[nMailbox];
Arrays.fill(mailboxes, CLOSED);
// open every even numbered mailbox starting from mailbox 2
for(int i = 2; i <= nMailbox; i++)
{
if(i % 2 == 0)
mailboxes[i] = OPEN;
}
// start from 3rd mailbox and change every 3rd box
// repeat the above process for all the boxes
for(int i = 3; i <= nMailbox; i++)
{
int j = i;
while(j < nMailbox)
{
if(mailboxes[j] == OPEN)
{
mailboxes[j] = CLOSED;
}
else if(mailboxes[j] == CLOSED)
{
mailboxes[j] = OPEN;
}
j += i;
}
}
int previous = 0;
for(int i = 0; i < nMailbox; i++)
{
if(mailboxes[i] == CLOSED)
{
System.out.println("Box #" + i + "; distance from previous box: " +
(i - previous));
previous = i;
}
}
}
}
****************************************************************** SCREENSHOT *********************************************************

Mailboxes Java Peter the postman was bored one evening and he decided to experiment with the...
For this c++ assignment, Overview write a program that will process two sets of numeric information. The information will be needed for later processing, so it will be stored in two arrays that will be displayed, sorted, and displayed (again). One set of numeric information will be read from a file while the other will be randomly generated. The arrays that will be used in the assignment should be declared to hold a maximum of 50 double or float elements....
Program 7 Arrays: building and sorting (100 points) Due: Friday, October 30 by 11:59 PM Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be...
Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...
1.2 Recruitment is one of the crucial functions of HRM. Based on the information provided below, how would you describe THE COMPANY’s approach to recruitment, before and after the implementation of the Brand Ambassador Program? How did the use of social media lead to the revision of the whole approach regarding recruitment? How ‘THE COMPANY’ Developed a Brand Ambassador Program At ‘THE COMPANY’ we usually categorize Employment Brand at ‘THE COMPANY’ into four big ‘buckets’: candidate experience, brand ambassador programs,...
Assignment 2 In this assignment, you will write two short programs to solve problems using recursion. 1. Initial Setup Log in to Unix. Run the setup script for Assignment 2 by typing: setup 2 2. Towers of Hanoi Legend has it that in a temple in the Far East, priests are attempting to move a stack of disks from one peg to another. The initial stack had 64 disks threaded onto one peg and arranged from bottom to top by...
could you please help me with this problem, also I
need a little text so I can understand how you solved the
problem?
import java.io.File; import java.util.Scanner; /** *
This program lists the files in a directory specified by * the
user. The user is asked to type in a directory name. * If the name
entered by the user is not a directory, a * message is printed and
the program ends. */ public class DirectoryList { public static...
I need help with my very last assignment of this term
PLEASE!!, and here are the instructions: After reading Chapter Two,
“Keys to Successful IT Governance,” from Roger Kroft and Guy
Scalzi’s book entitled, IT Governance in Hospitals and Health
Systems, please refer to the following assignment instructions
below.
This chapter consists of interviews with executives
identifying mistakes that are made when governing healthcare
information technology (IT). The chapter is broken down into
subheadings listing areas of importance to understand...