Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/scheduling/HighestResponseRatioNextScheduling.java (Java)

Code before:
package com.thealgorithms.scheduling;

import java.util.Arrays;
import java.util.Comparator;

/**
 * The HighestResponseRatioNextScheduling class implements
 * the Highest Response Ratio Next (HRRN) scheduling algorithm.
 * HRRN is a non-preemptive scheduling algorithm that
 * selects the process with the highest response ratio for execution.
 * The response ratio is calculated as (waiting time + burst time) / burst time.
 * This algorithm aims to reduce the average waiting time
 * and improve overall system performance by balancing short and long processes.
 */
public final class HighestResponseRatioNextScheduling {
    private HighestResponseRatioNextScheduling() {
    }

    /**
     * Calculates the Turn Around Time (TAT) for each process.
     *
     * @param processNames Array of process names.
     * @param arrivalTimes Array of arrival times corresponding to each process.
     * @param burstTimes   Array of burst times for each process.
     * @param noOfProcesses The number of processes.
     * @return An array of Turn Around Times for each process.
     */
    public static int[] calculateTurnAroundTime(String[] processNames, int[] arrivalTimes, int[] burstTimes, int noOfProcesses) {
        int currentTime = 0;
        int[] turnAroundTime = new int[noOfProcesses];
        boolean[] finishedProcess = new boolean[noOfProcesses];
        int finishedProcessCount = 0;

        // Sort by arrival times using a simple bubble sort for demonstration
        int[] sortedIndices = sortIndicesByArrival(arrivalTimes);
        arrivalTimes = Arrays.copyOf(arrivalTimes, arrivalTimes.length);
        burstTimes = Arrays.copyOf(burstTimes, burstTimes.length);
        processNames = Arrays.copyOf(processNames, processNames.length);

        // Reorder the arrays based on sorted indices
        int[] tempArrival = new int[noOfProcesses];
        int[] tempBurst = new int[noOfProcesses];
        String[] tempProcess = new String[noOfProcesses];

        for (int i = 0; i < noOfProcesses; i++) {

Review comment (performance):
This description can be rewrited to led more details.

It can be look like this:

```
/**
 * The {@code HighestResponseRatioNextScheduling} class implements the 
 * Highest Response Ratio Next (HRRN) scheduling algorithm. 
 * HRRN is a non-preemptive scheduling algorithm that selects the process with 
 * the highest response ratio for execution. 
 * The response ratio is calculated as:
 * 
 * <pre>
 *     Response Ratio = (waiting time + burst time) / burst time
 * </pre>
 * 
 * HRRN is designed to reduce the average waiting time and improve overall 
 * system performance by balancing between short and long processes, 
 * minimizing process starvation.
 */
```

Code after:
package com.thealgorithms.scheduling;

import java.util.Arrays;
import java.util.Comparator;

/**
 * The {@code HighestResponseRatioNextScheduling} class implements the
 * Highest Response Ratio Next (HRRN) scheduling algorithm.
 * HRRN is a non-preemptive scheduling algorithm that selects the process with
 * the highest response ratio for execution.
 * The response ratio is calculated as:
 *
 * <pre>
 *     Response Ratio = (waiting time + burst time) / burst time
 * </pre>
 *
 * HRRN is designed to reduce the average waiting time and improve overall
 * system performance by balancing between short and long processes,
 * minimizing process starvation.
 */
public final class HighestResponseRatioNextScheduling {

    private static final int PROCESS_NOT_FOUND = -1;
    private static final double INITIAL_MAX_RESPONSE_RATIO = -1.0;

    private HighestResponseRatioNextScheduling() {
    }

    /**
     * Represents a process in the scheduling algorithm.
     */
    private static class Process {
        String name;
        int arrivalTime;
        int burstTime;
        int turnAroundTime;
        boolean finished;

        Process(String name, int arrivalTime, int burstTime) {
            this.name = name;
            this.arrivalTime = arrivalTime;
            this.burstTime = burstTime;
            this.turnAroundTime = 0;
            this.finished = false;
        }