Peevish_Postman.java import java.util.*; /* * CPS 150 * Algorithms & Programming I * * Lab Project: The Peevish Postman Problem (Java Boolean Arrays) * * Name: */ public class Peevish_Postman { public static void main(String[] args) { boolean[] doors; final int NUM_DOORS = 100; final boolean OPEN = true; final boolean CLOSED = false; // Initialize the doors doors = new

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

This is the file:

 

// Peevish_Postman.java import java.util.*; /* * CPS 150 * Algorithms & Programming I * * Lab Project: The Peevish Postman Problem (Java Boolean Arrays) * * Name: */ public class Peevish_Postman { public static void main(String[] args) { boolean[] doors; final int NUM_DOORS = 100; final boolean OPEN = true; final boolean CLOSED = false; // Initialize the doors doors = new boolean[NUM_DOORS+1]; // We will not use doors[0] for (int i = 1; i <= NUM_DOORS; i++) { doors[i] = CLOSED; } // Print the initial state of each door (1-100) for (int i = 1; i <= NUM_DOORS; i++) { System.out.print("Door " + i + " is "); if (doors[i]) { System.out.println("open."); } else { System.out.println("closed."); } } // ADD YOUR CODE BETWEEN THIS LINE ... // ... AND THIS LINE // Print the final state of each door (1-100) for (int i = 1; i <= NUM_DOORS; i++) { System.out.print("Door " + i + " is "); if (doors[i]) { System.out.println("open."); } else { System.out.println("closed."); } } } // end main method } // end class Peevish_Postman

CPS 150 Lab Project 24: The
Peevish Postman Problem (Java
Boolean Arrays)
This lab project is due on Wednesday,
April 6, 2022, 12:30 pm.
British puzzle maker H. E. Dudeney
concocted an interesting puzzle about a
bored postman called the "Peevish Postman
Problem". According to Dudeney, the
postman worked in a small post office with
consecutive letter boxes numbered 1 to 100.
Each box was equipped with a door that
could be opened and closed. Late one
evening the postman made a "pass" through
the boxes and opened every door. Still
bored, he walked back to the beginning and
made a second pass, this time visiting boxes
2, 4, 6, .., 100. Since those doors were now
open, he closed them. On the third pass he
visited boxes 3, 6, 9, 12, ..., 99 and if a door
was open he closed it, and if the door was
closed he opened it. He continued to make
passes through the boxes and always
followed the same rule: On each pass i from
1 to 100, he visited only boxes that were
multiples of i, ... and changed the state of
each door he visited. After making 100
passes at the doors, he surveyed the results
and was surprised by the pattern of doors
that he saw.
The code below uses a boolean array to
represent the doors. A true value in the
array represents an open door, and a false
value represents a closed one.
Create a new Eclipse project named
Lab_Project_24, and download and import
the Peevish_Postman.java source code file.
Then, complete the code so that it simulates
the Peevish Postman problem as described
above. You will have to write two nested
loops in order to manipulate the array as
described above. The inner loop will control
the door number visited on a single pass,
and the outer loop will control the number
of passes.
The puzzle was conceived as a paper and
pencil entertainment. Can you
describe/explain the final pattern of doors?
Note: Because the doors are numbered
starting at one, we will waste the first
position (i.e., index 0) in the array. In this
case, the default value will be set to false. By
ignoring the first position, the door numbers
match their index positions in the array.
What Do I Hand In?
• Enter your explanation of the door
pattern in the space provided.
• Attach your completed source code
(Peevish Postman.java) file below.
Then click Submit.
Transcribed Image Text:CPS 150 Lab Project 24: The Peevish Postman Problem (Java Boolean Arrays) This lab project is due on Wednesday, April 6, 2022, 12:30 pm. British puzzle maker H. E. Dudeney concocted an interesting puzzle about a bored postman called the "Peevish Postman Problem". According to Dudeney, the postman worked in a small post office with consecutive letter boxes numbered 1 to 100. Each box was equipped with a door that could be opened and closed. Late one evening the postman made a "pass" through the boxes and opened every door. Still bored, he walked back to the beginning and made a second pass, this time visiting boxes 2, 4, 6, .., 100. Since those doors were now open, he closed them. On the third pass he visited boxes 3, 6, 9, 12, ..., 99 and if a door was open he closed it, and if the door was closed he opened it. He continued to make passes through the boxes and always followed the same rule: On each pass i from 1 to 100, he visited only boxes that were multiples of i, ... and changed the state of each door he visited. After making 100 passes at the doors, he surveyed the results and was surprised by the pattern of doors that he saw. The code below uses a boolean array to represent the doors. A true value in the array represents an open door, and a false value represents a closed one. Create a new Eclipse project named Lab_Project_24, and download and import the Peevish_Postman.java source code file. Then, complete the code so that it simulates the Peevish Postman problem as described above. You will have to write two nested loops in order to manipulate the array as described above. The inner loop will control the door number visited on a single pass, and the outer loop will control the number of passes. The puzzle was conceived as a paper and pencil entertainment. Can you describe/explain the final pattern of doors? Note: Because the doors are numbered starting at one, we will waste the first position (i.e., index 0) in the array. In this case, the default value will be set to false. By ignoring the first position, the door numbers match their index positions in the array. What Do I Hand In? • Enter your explanation of the door pattern in the space provided. • Attach your completed source code (Peevish Postman.java) file below. Then click Submit.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY