Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9151667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:51:30+00:00 2026-06-17T11:51:30+00:00

The list below is supposed to be result of my program. Though, for #2

  • 0

The list below is supposed to be result of my program. Though, for #2 I get “Homer opens the door”. I dont know if im staring right at the error. I’ve been studying the code for a while and being sleepy definitely doesnt help. Any help is appreciated!

  1. //Bart locks the door.
  2. //Homer tries to open the door, but can’t because its locked.
  3. //Homer unlocks the door.
  4. //Homer opens the door.
  5. //Bart tries to open the door, but can’t because its already open.
  6. //Marge closes the door.
  7. //Homer tries to close the door, but can’t because it is already
    closed.
  8. //Lisa opens the door.
  9. //Abraham tries to lock the door, but can’t because its open.
  10. //Marge closes the door.
  11. //Abraham locks the door.
  12. //Bart tries to open the door, but can’t because its locked.
  13. //Lisa tries to open the door, but can’t because its locked.
  14. //Homer tries to open the door, but can’t because its locked.
  15. //Abraham unlocks the door.
  16. //Homer opens the door.
  17. //Marge closes the door.

    //in a separate method:
    
    bart.lockDoor();
    homer.openDoor();
    homer.unlockDoor();
    homer.openDoor();
    bart.openDoor();
    marge.closeDoor();
    homer.closeDoor();
    lisa.openDoor();
    abraham.unlockDoor();
    marge.closeDoor();
    abraham.lockDoor();
    bart.openDoor();
    lisa.openDoor();
    homer.openDoor();
    abraham.unlockDoor();
    homer.openDoor();
    marge.closeDoor();
    
     boolean locked;
     boolean open;
    
     public void lockDoor()
    {
        if(locked == true)
            out.println( name + " tries to lock the door, but can't because its already locked.");
            else
                if(open == false)
                {
                    locked = true;
                    out.println( name + " locks the door.");
    
                }
    }
    
    public void unlockDoor()
    {
        if(open == true)
            out.println( name + " tries to unlock the door, but can't because its open.");
                else
                    if(locked == false)
                        out.println( name + " tries to unlock the door, but can't because its already unlocked.");
                        else
                            if(locked == true)
                            {
                                out.println( name + " unlocks the door.");
                                locked = false;
                            }
    
    }
    
    public void openDoor()
    {
        if(open == true)
            out.println( name + " tries to open the door, but can't because its already open.");
            else
                if( locked == true )
                    out.println( name + " tries to open the door, but can't because its locked.");
                    else
                        if(locked == false)
                        {
                            out.println( name + " opened the door.");
                            open = true;
                        }
    
    }
    
    public void closeDoor()
    {
        if(open == false)
            out.println( name + " tries to close the door, but can't because its already closed.");
            else
            {
                if(open == true)
                {
                    out.println( name + " closed the door.");
                    open = false;
                }
    
            }
    }
    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:51:31+00:00Added an answer on June 17, 2026 at 11:51 am

    You don’t specify language or a complete program, but it looks like the problem is that each person has (effectively) their own door, independent of each other person’s door, as each person has their own locked/open flags to track their door.

    If you want there to only be a single door, you need to get all the people to share a single locked and single open flag. Depending on the language you are using, you may be able to do that by making the flags static. Alternately, you could put them in a separate ‘door’ object and have all the ‘people’ objects refer that ‘door’

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im getting the following error for the piece of code below : expression list
The code below is supposed to show a stack of three list boxes, each
I have a list (see below) contained in a window. The window's DataContext has
I want to do the below list iteration in django templates: foo = ['foo',
I have a Generic List as below public static readonly List<Customer> Customers = new
When I click on the list-item below (li) I change the id of it
I'm appending to a list then throwing that list into a function below: List<ItemBean>
In below data list represents set of question's and answer, How to check whether
I have the following code below for list into master page <div id=header> <ul>
I wanted to generate a list view using below code. But after running this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.