Advertisement
iNoobAvicena

UTP Shortest Job First

Nov 21st, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. import java.util.Comparator;
  2. import java.util.LinkedList;
  3. import java.util.Scanner;
  4. import java.util.Collections;
  5.  
  6. public class ProcessMain {
  7.     public static void main(String[] args) {
  8.         Scanner in = new Scanner(System.in);
  9.         int n = in.nextInt();
  10.         in.nextLine();
  11.         LinkedList<Process> processes = new LinkedList<Process>();
  12.         //Lengkapi
  13.  
  14.         for (int x = 0; x < n; x++) {
  15.             Process temp = new Process(in.next(), in.nextInt());
  16.             processes.add(temp);
  17.         }
  18.  
  19.         Collections.sort(processes, Comparator.comparingInt(Process::getBurstTime));
  20.  
  21.         processes.forEach(System.out::println);
  22.         System.out.println("Semua process telah selesai dijalankan.");
  23.     }
  24. }
  25.  
  26. class Process {
  27.  
  28.     private final String processName;
  29.     private final int burstTime;
  30.  
  31.     public Process(String processName, int burstTime) {
  32.         //Lengkapi
  33.         this.processName = processName;
  34.         this.burstTime = burstTime;
  35.     }
  36.  
  37.     public int getBurstTime() {
  38.         //Lengkapi
  39.         return burstTime;
  40.     }
  41.  
  42.     public String getProcessName() {
  43.         //Lengkapi
  44.         return processName;
  45.     }
  46.  
  47.     @Override
  48.     public String toString() {
  49.         return processName + " dijalankan sebanyak "
  50.                 + burstTime + " burst time.";
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement