Guest User

Untitled

a guest
Mar 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. public Schedule generateSchedule(int totalHours, int totalMin) {
  2. // method is going to check if there is enought bussines hours
  3. if (!checkEnoughtTimeOnWeek(totalHours, totalMin)) {
  4.  
  5. Schedule schedule = new Schedule();
  6. // default constructor for Time is off
  7. schedule.setMonday(new Time());
  8. schedule.setTuesday(new Time());
  9. schedule.setWednesday(new Time());
  10. schedule.setThursday(new Time());
  11. schedule.setFriday(new Time());
  12. schedule.setSaturday(new Time());
  13. schedule.setSunday(new Time());
  14. // return schedule with 0 hours and 0 minutes
  15. return schedule;
  16. }
  17. // return generato schedule
  18. Schedule schedule = openingOrClosing();
  19.  
  20. return schedule;
  21. }
  22.  
  23. // checking if there is enought time on week for requested amount of hours
  24. private boolean checkEnoughtTimeOnWeek(int totalHours, int totalMin) {
  25. // adding hours to minutes
  26. int minutes = totalMin + (totalHours * 60);
  27. // totalOfPossibleHoursWork if its greater then you
  28. // can generate schedule
  29. if (totalOfPossibleHoursWork() > minutes) {
  30. this.totalMinutesPerWeek = totalMin + (totalHours * 60);
  31. divideTime();// divide time randomly
  32. return true;
  33. }
  34. return false;// not enoguth time
  35. }
  36. // getting total minutes from bussines
  37. private int totalOfPossibleHoursWork(){
  38. int totalMinutes = 0;
  39. int totalHours = 0;
  40. // check if they want to get this time off
  41. if(!mondayoff){
  42. totalHours = bussinesWeek.getMondayTime().getTotalHours();
  43. totalMinutes = bussinesWeek.getMondayTime().getTotalMinutes();
  44. }
  45. // check if they want to get this time off
  46. if(!tuesdayOff){
  47. totalHours = totalHours + bussinesWeek.getTuesdayTime().getTotalHours();
  48. totalMinutes = totalMinutes + bussinesWeek.getTuesdayTime().getTotalMinutes();
  49. }
  50. // check if they want to get this time off
  51. if(!wednesdayOff){
  52. totalHours = totalHours + bussinesWeek.getWednesdayTime().getTotalHours();
  53. totalMinutes = totalMinutes + bussinesWeek.getWednesdayTime().getTotalMinutes();
  54. }
  55. // check if they want to get this time off
  56. if(!ThursdayOff){
  57. totalMinutes = totalMinutes + bussinesWeek.getThursdayTime().getTotalMinutes();
  58. totalHours = totalHours + bussinesWeek.getThursdayTime().getTotalHours();
  59. }
  60. // check if they want to get this time off
  61. if(!fridayOff){
  62. totalMinutes = totalMinutes + bussinesWeek.getFridayTime().getTotalMinutes();
  63. totalHours = totalHours + bussinesWeek.getFridayTime().getTotalHours();
  64. }
  65. // check if they want to get this time off
  66. if(!saturdayOff){
  67. totalMinutes = totalMinutes + bussinesWeek.getSaturdayTime().getTotalMinutes();
  68. totalHours = totalHours + bussinesWeek.getSaturdayTime().getTotalHours();
  69. }
  70. // check if they want to get this time off
  71. if(!sundaOff){
  72. totalMinutes = totalMinutes + bussinesWeek.getSundayTime().getTotalMinutes();
  73. totalHours = totalHours + bussinesWeek.getSundayTime().getTotalHours();
  74. }
  75. // adding hours to minute
  76. int num = totalMinutes + (totalHours * 60);
  77. return num ;
  78. }
Add Comment
Please, Sign In to add comment