### Instruction:
Write a Java program that simulates a basic CPU scheduler using the Round Robin scheduling algorithm. The program should accept a list of processes with their arrival times, burst times, and priorities, and output the order in which they are executed, along with average waiting time and turnaround time.


### Response:

Here's a Java program that simulates a basic CPU scheduler using the Round Robin scheduling algorithm:

```java
import java.util.*;

class Process {
    int id, arrivalTime, burstTime, priority;
    int remainingBurstTime;

    public Process(int id, int arrivalTime, int burstTime, int priority) {
        this.id = id;
        this.arrivalTime = arrivalTime;
        this.burstTime = burstTime;
        this.priority = priority;
        this.remainingBurstTime = burstTime;
    }
}

public class RoundRobinScheduler {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter number of processes: ");
        int numProcesses = scanner.nextInt();

        List<Process> processList = new ArrayList<>();
        for (int i = 0; i < numProcesses; i++) {
            System.out.println("Enter details for process " + (i + 1));
            System.out.print("Arrival time: ");
            int arrivalTime = scanner.nextInt();
            System.out.print("Burst time: ");
            int burstTime = scanner.nextInt();
            System.out.print("Priority: ");
            int priority = scanner.nextInt();

            processList.add(new Process(i + 1, arrivalTime, burstTime, priority));
        }

        System.out.print("Enter time quantum: ");
        int timeQuantum = scanner.nextInt();

        roundRobinScheduling(processList, timeQuantum);
    }

    private static void roundRobinScheduling(List<Process> processList, int timeQuantum) {
        int currentTime = 0;
        int completedProcesses = 0;
        int totalWaitingTime = 0;
        int totalTurnaroundTime = 0;

        Queue<Process> readyQueue = new LinkedList<>();

        while (completedProcesses < processList.size()) {
            // Add arrived processes to the ready queue
            for (Process process : processList) {
                if (process.arrivalTime == currentTime && !readyQueue.contains(process)) {
                    readyQueue.add(process);
                }
            }

            // Execute the first process in the ready queue
            if (!readyQueue.isEmpty()) {
                Process currentProcess = readyQueue.poll();
                System.out.println("Executing process " + currentProcess.id);

                int timeSlice = Math.min(timeQuantum, currentProcess.remainingBurstTime);
                currentTime += timeSlice;
                currentProcess.remainingBurstTime -= timeSlice;

                // Check if the process is completed
                if (currentProcess.remainingBurstTime == 0) {
                    completedProcesses++;
                    totalWaitingTime += currentTime - currentProcess.arrivalTime - currentProcess.burstTime;
                    totalTurnaroundTime += currentTime - currentProcess.arrivalTime;
                } else {
                    // Add the process back to the ready queue
                    readyQueue.add(currentProcess);
                }
            } else {
                currentTime++;
            }
        }

        double averageWaitingTime = (double) totalWaitingTime / processList.size();
        double averageTurnaroundTime = (double) totalTurnaroundTime / processList.size();

        System.out.printf("Average waiting time: %.2f\n", averageWaitingTime);
        System.out.printf("Average turnaround time: %.2f\n", averageTurnaroundTime);
    }
}
```

This program accepts a list of processes with their arrival times, burst times, and priorities. It then simulates the Round Robin scheduling algorithm using a specified time quantum and outputs the order in which the processes are executed, along with the average waiting time and turnaround time.

Please note that this code does not handle any input validation or error handling, so make sure to provide valid inputs when running the program.