Advertisement
Guest User

Job Class

a guest
Aug 17th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.88 KB | None | 0 0
  1. package system.domain;
  2.  
  3. public class Job {
  4.     private final int MAX_TIME = 10;
  5.     private int jobId;
  6.     private int startTime;
  7.     private int finishTime;
  8.     private int duration;
  9.     private int profit;
  10.    
  11.     public Job() {
  12.     }
  13.    
  14.     public Job(int jobId, int startTime, int finishTime, int profit) {
  15.         if (startTime < 0 || finishTime < 0) {
  16.             throw new TimeConstraintException("Start Time and Finish Time must be positive number");
  17.         }
  18.         else if (startTime > MAX_TIME || finishTime > MAX_TIME) {
  19.             throw new TimeConstraintException("Start Time and Finish Time must less than 10 unit of time");
  20.         }
  21.         else if (startTime >= finishTime) {
  22.             throw new TimeConstraintException("Start Time is larger than or equal to Finish Time");
  23.         }
  24.         else if (profit < 0) {
  25.             throw new ProfitNegativeException("Profit must be positive number");
  26.         }
  27.         else {
  28.             this.jobId = jobId;
  29.             this.startTime = startTime;
  30.             this.finishTime = finishTime;
  31.             this.setDuration();
  32.             this.profit = profit;          
  33.         }
  34.     }
  35.  
  36.     public int getJobId() {
  37.         return this.jobId;
  38.     }
  39.    
  40.     public boolean setJobId(int jobId) {
  41.         this.jobId = jobId;
  42.         return true;
  43.     }
  44.    
  45.     public int getStartTime() {
  46.         return this.startTime;
  47.     }
  48.    
  49.     public boolean setStartTime(int startTime) {
  50.         if (startTime < 0) {
  51.             throw new TimeConstraintException("Start Time and Finish Time must be positive number");
  52.         }
  53.         else if (startTime > MAX_TIME) {
  54.             throw new TimeConstraintException("Start Time and Finish Time must less than 10 unit of time");
  55.         }
  56.         else if (startTime > this.finishTime) {
  57.             throw new TimeConstraintException("Start Time is larger than Finish Time");
  58.         }
  59.         else {
  60.             this.startTime = startTime;
  61.             return true;           
  62.         }
  63.     }
  64.    
  65.     public int getFinishTime() {
  66.         return this.finishTime;
  67.     }
  68.    
  69.     public boolean setFinishTime(int finishTime) {
  70.         if (finishTime < 0) {
  71.             throw new TimeConstraintException("Start Time and Finish Time must be positive number");
  72.         }
  73.         else if (finishTime > MAX_TIME) {
  74.             throw new TimeConstraintException("Start Time and Finish Time must less than 10 unit of time");
  75.         }
  76.         else if (this.startTime > finishTime) {
  77.             throw new TimeConstraintException("Start Time is larger than Finish Time");
  78.         }
  79.         else {
  80.             this.finishTime = finishTime;
  81.             return true;           
  82.         }
  83.     }
  84.    
  85.     public int getDuration() {
  86.         return this.duration;
  87.     }
  88.    
  89.     private boolean setDuration() {
  90.         this.duration = this.finishTime - this.startTime;
  91.         return true;
  92.     }
  93.    
  94.     public int getProfit() {
  95.         return this.profit;
  96.     }
  97.    
  98.     public boolean setProfit (int profit) {
  99.         if (profit < 0) {
  100.             throw new ProfitNegativeException("Profit must be positive number");
  101.         }
  102.         else {
  103.             this.profit = profit;
  104.             return true;
  105.         }
  106.     }
  107.    
  108.     public String toString() {
  109.         return Integer.toString(this.jobId) + " " +
  110.                 Integer.toString(this.startTime) + " " +
  111.                 Integer.toString(this.finishTime) + " " +
  112.                 Integer.toString(this.profit);
  113.     }
  114.    
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement