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

  • Home
  • SEARCH
  • 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 7716817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:43:37+00:00 2026-06-01T02:43:37+00:00

Create a method named getNextProjectIndex() that returns an int that gets the next index

  • 0

Create a method named getNextProjectIndex() that returns an int that
gets the next index of the projects array that contains a -1.0. Find
the next item in the projects array that contains a -1.0 and return
that index of the array. This method should return -1 if the array is
full. -1 is a common flag to indicate failure in methods that should
only return non-negative integers.

I am having trouble calling this method in my main method. Does the problem lie in my getNextProjectIndex method or my main method in how I am calling it?

  public double getNextProjectIndex()
  {
    int i = 0;
    int full = -1;
    while(i < projects.length)
    {
      if (projects[i] == -1)
      {

        return i;
      }
      else if (i == (projects.length - 1) && projects[i] != -1)
      {
        return full;
      }

    }

    return i;

  }

Here is my main method:

public class Main {

  public static void main(String [ ] args)
  {
    Student testStudent = new Student("BL", "Hill", 34);
    int i = 0;
    System.out.println(testStudent.getFname() + " " + testStudent.getLname() );

    while(i < 5)
    {
      if(testStudent.getNextProjectIndex() != 0)
      {      
        testStudent.setProjectScore(10.0, i);
        System.out.println("Scores are: "+ testStudent.getProjectScore(i));
      }  


      i++;
    }


  }

}

When the program is run only one score is displayed rather than 5 scores. It does not completely run through the loop. Only -1 should be returned from that method if ALL slots in the array are filled.

  • 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-01T02:43:39+00:00Added an answer on June 1, 2026 at 2:43 am

    I am guessing that your program hangs. In the while loop in getNextProjectIndex(), i is never incremented, thus causing an infinite loop.

    –Edit–
    Also, you have some cruft in the method try:

    public int getNextProjectIndex()
    {
      int i = 0;
      while(i < projects.length) {
        if (projects[i] == -1)
          return i;
        ++i;
      }
      return -1;
    }
    

    –Edit– changed to while loop, since that’s apparently required.

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

Sidebar

Related Questions

Im trying to create a method that take 2 int array as the input
This program is in response to the assignment: Create a method named Sum() that
How can I create a method that has optional parameters in it in Visual
I want to create a method sum that I can call on different types,
Is it possible to create a method like BitConverter.GetBytes() that accepts as input also
I have a WCF RIA Domain Service that contains a method I'd like to
I need to create a recursive Boolean method named isMemeber. The method should accept
Using reflection (i'm guessing?), is it possible to create a method that will return
I Create a class named DataClass there i have this method +(NSMutableArray*) returnList :(NSString
I need to create a structure that looks like an int (but has an

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.