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

Code before:
            tempProcess[i] = processNames[sortedIndices[i]];
        }

        arrivalTimes = tempArrival;
        burstTimes = tempBurst;
        processNames = tempProcess;

        while (finishedProcessCount < noOfProcesses) {
            currentTime = Math.max(currentTime, arrivalTimes[findNextProcess(arrivalTimes, finishedProcess, currentTime)]);
            int loc = findHighestResponseRatio(processNames, arrivalTimes, burstTimes, finishedProcess, currentTime);

            turnAroundTime[loc] = currentTime + burstTimes[loc] - arrivalTimes[loc];
            currentTime += burstTimes[loc];
            finishedProcess[loc] = true;
            finishedProcessCount++;
        }

        return turnAroundTime;
    }

    /**
     * Calculates the Waiting Time (WT) for each process.
     *
     * @param turnAroundTime The Turn Around Times for each process.
     * @param burstTimes     The burst times for each process.
     * @return An array of Waiting Times for each process.
     */
    public static int[] calculateWaitingTime(int[] turnAroundTime, int[] burstTimes) {
        int[] waitingTime = new int[turnAroundTime.length];
        for (int i = 0; i < turnAroundTime.length; i++) {
            waitingTime[i] = turnAroundTime[i] - burstTimes[i];
        }
        return waitingTime;
    }

    /**
     * Finds the next process to be scheduled based on arrival times and the current time.
     *
     * @param arrivalTimes    Array of arrival times for each process.
     * @param finishedProcess Array indicating whether each process has finished.
     * @param currentTime     The current time in the scheduling process.
     * @return The index of the next process to be scheduled.
     */
    private static int findNextProcess(int[] arrivalTimes, boolean[] finishedProcess, int currentTime) {
        for (int i = 0; i < arrivalTimes.length; i++) {
            if (!finishedProcess[i] && arrivalTimes[i] <= currentTime) {
                return i;
            }
        }
        return 0;
    }

Review comment (suggestion):
Rather than keeping track of processes using separate arrays for names, burst times, and arrival times, it would be better to encapsulate these details in a Process class. This would make the algorithm easier to understand and extend.

This class can look like:

```
class Process {
    String name;
    int arrivalTime;
    int burstTime;
    int turnAroundTime;
    boolean finished;
}
```
But maybe with some remarks.
And maybe inside this class can be placed method for response ration calculation.

Code after:
         * Calculates the response ratio for this process.
         *
         * @param currentTime The current time in the scheduling process.
         * @return The response ratio for this process.
         */
        double calculateResponseRatio(int currentTime) {
            return (double) (burstTime + currentTime - arrivalTime) / burstTime;
        }
    }

    /**
     * Calculates the Turn Around Time (TAT) for each process.
     *
     * <p>Turn Around Time is calculated as the total time a process spends
     * in the system from arrival to completion. It is the sum of the burst time
     * and the waiting time.</p>
     *
     * @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(final String[] processNames, final int[] arrivalTimes, final int[] burstTimes, final int noOfProcesses) {
        int currentTime = 0;
        int[] turnAroundTime = new int[noOfProcesses];
        Process[] processes = new Process[noOfProcesses];

        for (int i = 0; i < noOfProcesses; i++) {
            processes[i] = new Process(processNames[i], arrivalTimes[i], burstTimes[i]);
        }

        Arrays.sort(processes, Comparator.comparingInt(p -> p.arrivalTime));

        int finishedProcessCount = 0;
        while (finishedProcessCount < noOfProcesses) {
            int nextProcessIndex = findNextProcess(processes, currentTime);
            if (nextProcessIndex == PROCESS_NOT_FOUND) {
                currentTime++;
                continue;
            }

            Process currentProcess = processes[nextProcessIndex];
            currentTime = Math.max(currentTime, currentProcess.arrivalTime);
            currentProcess.turnAroundTime = currentTime + currentProcess.burstTime - currentProcess.arrivalTime;
            currentTime += currentProcess.burstTime;
            currentProcess.finished = true;
            finishedProcessCount++;
        }

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