Advertisement
LeeSeng

Worker

Aug 17th, 2019
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. package system.domain;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.LinkedList;
  5. import java.util.List;
  6.  
  7. public class Worker {
  8.     private int workerId;
  9.     private List<Boolean> ScheduledTime;
  10.     private int idleTime;
  11.     private int profitWorkerMade;
  12.     private final static int MAX_SIZE = 10;
  13.    
  14.     public Worker(int workerId) {
  15.         this.workerId = workerId;
  16.         ScheduledTime = new ArrayList<>();
  17.     }
  18.    
  19.     public void assginJob(LinkedList<Job> jobSequenced, int maxProfit) {
  20.         for (int i = 0; i < MAX_SIZE; i++) {
  21.             ScheduledTime.add(null);
  22.         }
  23.        
  24.         for (Job job : jobSequenced) {
  25.             int startTime, duration, assigningTime;
  26.             startTime = job.getStartTime();
  27.             duration = job.getDuration();
  28.             assigningTime = startTime;
  29.            
  30.             while (!(duration == 0)) {
  31.                 ScheduledTime.set(assigningTime, true);
  32.                 --duration;
  33.                 ++assigningTime;
  34.             }
  35.         }
  36.        
  37.         for (int i = 0; i < MAX_SIZE; i++) {
  38.             if (ScheduledTime.get(i) == null) ScheduledTime.set(i, false);
  39.         }
  40.        
  41.         this.calculateIdleTime();
  42.         this.calculateProfitWorkerMade(maxProfit);
  43.     }
  44.    
  45.     private void calculateIdleTime() {
  46.         this.idleTime = 0;
  47.         for (Boolean time : ScheduledTime) {
  48.             if (time == false) idleTime++;
  49.         }
  50.     }
  51.    
  52.     private void calculateProfitWorkerMade(int maxProfit) {
  53.         this.profitWorkerMade = maxProfit - this.idleTime;
  54.     }
  55.    
  56.     public int getWorkerId() {
  57.         return this.workerId;
  58.     }
  59.    
  60.     public int getIdleTime() {
  61.         return this.idleTime;
  62.     }
  63.    
  64.     public int getProfitWorkerMade() {
  65.         return this.profitWorkerMade;
  66.     }
  67.    
  68.     public List<Boolean> getScheduledTime() {
  69.         return this.ScheduledTime;
  70.     }
  71.    
  72.     public String toString() {
  73.         return "Worker " + this.getWorkerId() + " can make profit of " + this.getProfitWorkerMade() + " unit of profit. \n" +
  74.                 "Worker " + this.getWorkerId() + " idle for " + this.getIdleTime() + " unit of time. \n" +
  75.                 this.ScheduledTime + "\n";
  76.     }
  77.    
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement