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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:12:13+00:00 2026-05-28T17:12:13+00:00

Just having a hard time adding a certain bit of given code to add

  • 0

Just having a hard time adding a certain bit of given code to add an extra check to a preexisting method.

public boolean makeAppointment(int time,
                               Appointment appointment)
{
    if(validTime(time)) {
        int startTime = time - START_OF_DAY;
        if(appointments[startTime] == null) {
            int duration = appointment.getDuration();
            // Fill in all the slots for the full duration
            // of the appointment.
            for(int i = 0; i < duration; i++) {
                appointments[startTime + i] = appointment;
            }
            return true;
        }
        else {

            return false;
        }
    }
    else {
        return false;
    }
}

Is the main makeAppointment method. I need to add a method that checks if one appoints duration overlaps that of another. If I have two appointments: 1 is at 5PM and lasts 2 hours, the other is at 6 PM and only last one hour. I need to add the following method into this preexisting code to prevent this from happening.

private boolean checkMultihourAppointment(int startTime, int duration){

Thats the header for it. I have tried to implement it, but it ends up failing every Junit test.

Need any more info, please ask 🙂

  • 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-05-28T17:12:14+00:00Added an answer on May 28, 2026 at 5:12 pm

    Is this what you want? Rewrite your existing code to add checkmethod.

    public boolean makeAppointment(int time,
                                   Appointment appointment)
    {
        if(validTime(time)) {
            int startTime = time - START_OF_DAY;
            int duration = appointment.getDuration();
            if(checkMultihourAppointment(startTime, duration)) {
                // Fill in all the slots for the full duration
                // of the appointment.
                for(int i = 0; i < duration; i++) {
                    appointments[startTime + i] = appointment;
                }
                return true;
            }
            else {
    
                return false;
            }
        }
        else {
            return false;
        }
    }
    
    private boolean checkMultihourAppointment(int startTime, int duration){
        for(int i = 0; i < duration; i++) {
              if(appointments[startTime + i] != null) return false;
        }
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just come across the following line of code and having a hard time finding
I'm having a hard time getting my head around this, and Google just isn't
I just start playing with GWT I'm having a really hard time to make
I have this code I been working on but I'm having a hard time
I am just having hard time understanding the difference between virutal memory vs physical
i'm having a hard time squeezing my alert dialog to just wrap my content.
I'm having a hard time describing this problem. Maybe that's why I'm having a
I'm having a very hard time trying to access a custom configuration section in
I've made a basic cart for my web app, I'm just having a hard
I'm having a hard time converting a NodeList to an array in IE 8.

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.