Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I think this part is wrong. I still got another output. What am I wrong? /** * T

ID: 3920617 • Letter: I

Question

I think this part is wrong. I still got another output. What am I wrong?

/**
     * This places up to startingSharks sharks in the sharks array. This randomly chooses a
     * location and age for each shark.
     * Algorithm:
     * For each shark this tries to place
     *     reset the attempts to place the particular shark to 0.
     *     Try to place a single shark up to Config.MAX_PLACE_ATTEMPTS times
     *          Randomly choose a row, then column using randGen.nextInt( ) with the appropriate shark
     *          array dimension as the parameter.
     *          Increment the number of attempts to place the shark.
     *          If the location is empty in both the fish array and sharks array then
     *              place the shark in that location, randomly choosing its age from 0 up to
     *              and including sharkBreed.
     *          If the location is already occupied, generate another location and try again.
     *     On the Config.MAX_PLACE_ATTEMPTS try, whether or not the shark is successfully placed,
     *     stop trying to place additional sharks.
     * Return the number of sharks actually placed.     *   
     *
     * @param fish The array containing all the ages of all the fish.
     * @param sharks The array containing all the ages of all the sharks.
     * @param startingSharks The number of sharks to attempt to place in the sharks array.
     * @param sharksBreed The age at which sharks breed.
     * @param randGen The random number generator.
     * @return the number of sharks actually placed.
     */
    public static int placeSharks(int[][] fish, int[][] sharks, int startingSharks,
            int sharksBreed, Random randGen) {
            int numSharksPlaced = 0;
         
            int attempt = 0;
   
            for(int i=0; i< startingSharks; i++){
                attempt = 0;
                while(attempt <= Config.MAX_PLACE_ATTEMPTS){
                    int row = randGen.nextInt(sharks.length);
                    int col = randGen.nextInt(sharks[0].length);
                    attempt++;
                    //if empty
                    if((fish[row][col] == -1) && (sharks[row][col] == -1)){
                        int age = randGen.nextInt(sharksBreed + 1);
                        sharks[row][col] = age;
                        numSharksPlaced++;
                        break;
                    }
                  
                  
                  
                }
                if (attempt >= Config.MAX_PLACE_ATTEMPTS) {
                    return numSharksPlaced;
                  
                }
            }
         
            return numSharksPlaced;
        }

Explanation / Answer

I have no clue on what other classes are and ther emight be the case when your input to this function itself is wrong.. however based on the comments to the method.. i am trying to suggest below changes: