Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Schedule generateSchedule(int totalHours, int totalMin) {
- // method is going to check if there is enought bussines hours
- if (!checkEnoughtTimeOnWeek(totalHours, totalMin)) {
- Schedule schedule = new Schedule();
- // default constructor for Time is off
- schedule.setMonday(new Time());
- schedule.setTuesday(new Time());
- schedule.setWednesday(new Time());
- schedule.setThursday(new Time());
- schedule.setFriday(new Time());
- schedule.setSaturday(new Time());
- schedule.setSunday(new Time());
- // return schedule with 0 hours and 0 minutes
- return schedule;
- }
- // return generato schedule
- Schedule schedule = openingOrClosing();
- return schedule;
- }
- // checking if there is enought time on week for requested amount of hours
- private boolean checkEnoughtTimeOnWeek(int totalHours, int totalMin) {
- // adding hours to minutes
- int minutes = totalMin + (totalHours * 60);
- // totalOfPossibleHoursWork if its greater then you
- // can generate schedule
- if (totalOfPossibleHoursWork() > minutes) {
- this.totalMinutesPerWeek = totalMin + (totalHours * 60);
- divideTime();// divide time randomly
- return true;
- }
- return false;// not enoguth time
- }
- // getting total minutes from bussines
- private int totalOfPossibleHoursWork(){
- int totalMinutes = 0;
- int totalHours = 0;
- // check if they want to get this time off
- if(!mondayoff){
- totalHours = bussinesWeek.getMondayTime().getTotalHours();
- totalMinutes = bussinesWeek.getMondayTime().getTotalMinutes();
- }
- // check if they want to get this time off
- if(!tuesdayOff){
- totalHours = totalHours + bussinesWeek.getTuesdayTime().getTotalHours();
- totalMinutes = totalMinutes + bussinesWeek.getTuesdayTime().getTotalMinutes();
- }
- // check if they want to get this time off
- if(!wednesdayOff){
- totalHours = totalHours + bussinesWeek.getWednesdayTime().getTotalHours();
- totalMinutes = totalMinutes + bussinesWeek.getWednesdayTime().getTotalMinutes();
- }
- // check if they want to get this time off
- if(!ThursdayOff){
- totalMinutes = totalMinutes + bussinesWeek.getThursdayTime().getTotalMinutes();
- totalHours = totalHours + bussinesWeek.getThursdayTime().getTotalHours();
- }
- // check if they want to get this time off
- if(!fridayOff){
- totalMinutes = totalMinutes + bussinesWeek.getFridayTime().getTotalMinutes();
- totalHours = totalHours + bussinesWeek.getFridayTime().getTotalHours();
- }
- // check if they want to get this time off
- if(!saturdayOff){
- totalMinutes = totalMinutes + bussinesWeek.getSaturdayTime().getTotalMinutes();
- totalHours = totalHours + bussinesWeek.getSaturdayTime().getTotalHours();
- }
- // check if they want to get this time off
- if(!sundaOff){
- totalMinutes = totalMinutes + bussinesWeek.getSundayTime().getTotalMinutes();
- totalHours = totalHours + bussinesWeek.getSundayTime().getTotalHours();
- }
- // adding hours to minute
- int num = totalMinutes + (totalHours * 60);
- return num ;
- }
Add Comment
Please, Sign In to add comment