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 8875423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:58:18+00:00 2026-06-14T18:58:18+00:00

My piece of code will take a Patient object, and loop through an array

  • 0

My piece of code will take a Patient object, and loop through an array which stores patient object and if it matches, it will print out the message on the if statement which is all good. But If the patient is not there, I believe the else segment will print out everytime the patient is not in the waitinglist array. What I’m trying to accomplish is to make the “your patient is not on the waiting list” print once if it’s not in the array? Any idea how to do this? I tried to think about a way to do this, but I believe there is a simple solution that my brain cannot just figure out.

public int findWaitingPosition (Patient patient)
{
    for (int i=0 ; i <= waitingList.length-1 ; i++)
    {
        if (waitingList[i].equals(patient))
        {
            System.out.println ("The patient is on waiting list: " + i+1);
        }
        else
        {
            System.out.println ("Your patient is not on the waiting list");
        }

    }
  • 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-14T18:58:19+00:00Added an answer on June 14, 2026 at 6:58 pm

    I would use a temporary variable. Also it looks like your method is supposed to return the position of the patient in the array. In this snippet -1 means not found.

    public int findWaitingPosition (Patient patient)
    {
        int position = -1;
        for (int i=0 ; i <= waitingList.length-1 ; i++)
        {
            if (waitingList[i].equals(patient))
            {
                position = i;
                break;
            }
        }
        if (position >= 0)
            System.out.println ("The patient is on waiting list: " + i+1);
        else
            System.out.println ("Your patient is not on the waiting list");
    
        return position;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of code which I'm hoping will be able to tell
I have a piece of code that will take a string and repeat it
I'm trying to write a piece of code that will do the following: Take
I have a piece of code which allows me to take a single string
I've made this piece of code, it will re-size images on the fly, if
Is there a web site or tool that will convert a piece PHP code
I am getting an error from a piece of code. I will only show
This piece of code is supposed to go through a list and preform some
This piece of code gives a syntax error at the colon of elif process.loop(i,
I would like to write a piece of code which checks, for each network

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.