Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions 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. ]
expand button
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
Check Mark
Knowledge Booster
Background pattern image
Similar questions
    Recommended textbooks for you
    Text book image
    Computer Networking: A Top-Down Approach (7th Edi...
    Computer Engineering
    ISBN:9780133594140
    Author:James Kurose, Keith Ross
    Publisher:PEARSON
    Text book image
    Computer Organization and Design MIPS Edition, Fi...
    Computer Engineering
    ISBN:9780124077263
    Author:David A. Patterson, John L. Hennessy
    Publisher:Elsevier Science
    Text book image
    Network+ Guide to Networks (MindTap Course List)
    Computer Engineering
    ISBN:9781337569330
    Author:Jill West, Tamara Dean, Jean Andrews
    Publisher:Cengage Learning
    Text book image
    Concepts of Database Management
    Computer Engineering
    ISBN:9781337093422
    Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
    Publisher:Cengage Learning
    Text book image
    Prelude to Programming
    Computer Engineering
    ISBN:9780133750423
    Author:VENIT, Stewart
    Publisher:Pearson Education
    Text book image
    Sc Business Data Communications and Networking, T...
    Computer Engineering
    ISBN:9781119368830
    Author:FITZGERALD
    Publisher:WILEY