0

I'm trying to write a loop that checks each element in an array that contains test scores. If the test score meets the threshold then it should return true or false in that location. Here's the code so far. I felt I was on the right track and understand how it should be done but don't know enough Java to do so.

public class SimpleArray {

  /**
   * Write a function that takes in an applicant's numerical scores and returns
   * Boolean values to tell us if they are above a certain threshold.
   * 
   * For example, if the applicant's scores are [80, 85, 89, 92, 76, 81], and the
   * threshold value is 85, return [false, false, true, true, false, false].
   * 
   * @param scores    The applicant's array of scores
   * @param threshold The threshold value
   * @return An array of boolean values: true if the score is higher than
   *         threshold, false otherwise
   */
  public static boolean[] applicantAcceptable(int[] scores, int threshold) {
  
    boolean[] highScores = new boolean[scores.length];

    /*
     * TO DO: The output array, highScores, should hold as its elements the
     * appropriate boolean (true or false) value.
     *
     * Write a loop to compute the acceptability of the scores based on the
     * threshold and place the result into the output array.
     */
    for (int i = 0; i < highScores.length; i++){
      if (highScores[i] <= threshold[i]);


      return highScores;

  }
}
4
  • You are not changing the values in highScores in any way. Commented Sep 25, 2021 at 20:58
  • @Progman no I'm not changing the scores. There is a test case open with values already given to me and a threshold. My loop needs to check each score in the array and return true or false for any that doesn't meet the threshold Commented Sep 25, 2021 at 21:05
  • @alexquintanilla Mark as accepted answer if it solved your problem. Commented Sep 25, 2021 at 21:07
  • 1
    @Zakk you're awesome thank you! Commented Sep 25, 2021 at 21:15

1 Answer 1

2

Simply assign the value of scores[i] > threshold to your bool array:

boolean[] highScores = new boolean[scores.length];

for (int i = 0; i < highScores.length; i++)
    highScores[i] = scores[i] > threshold;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.