Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.69 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class DieterTest {
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner kbd = new Scanner(System.in);
  8.  
  9.         String sat = "Saturday";
  10.         String sun = "Sunday";
  11.  
  12.         //Ask name
  13.         System.out.println("Name employee: ");
  14.         String name = kbd.next();
  15.  
  16.         //Ask startday
  17.         System.out.println("Enter day (...day)");
  18.         String startDayName = kbd.next();
  19.  
  20.         //Ask starting date in the right format
  21.         System.out.println("Enter starting date (dd mm)");
  22.         int startDay = kbd.nextInt();
  23.         int startMonth = kbd.nextInt();
  24.  
  25.         //Ask starting time in the right format
  26.         System.out.println("Enter starting time (hh mm): ");
  27.         int startHour = kbd.nextInt();
  28.         int startMinutes = kbd.nextInt();
  29.  
  30.  
  31.         //Ask endday
  32.         System.out.println("Enter day (...day)");
  33.         String endDayName = kbd.next();
  34.  
  35.         //Ask ending date in the right format
  36.         System.out.println("Enter ending date (dd mm)");
  37.         int endDay = kbd.nextInt();
  38.         int endMonth = kbd.nextInt();
  39.  
  40.         //Ask ending time in right format
  41.         System.out.println("Enter ending time (hh mm): ");
  42.         int endHour = kbd.nextInt();
  43.         int endMinutes = kbd.nextInt();
  44.  
  45.  
  46.  
  47.         //Calculate hours
  48.         int workedHours = endHour - startHour;
  49.         if (workedHours < 0) {
  50.             workedHours += 24;
  51.         } else if(endMinutes<startMinutes&&workedHours==0){
  52.             workedHours += 24;
  53.         }
  54.  
  55.         //Calculate minutes
  56.         int workedMinutes = endMinutes - startMinutes;
  57.         if (workedMinutes < 0) {
  58.             workedMinutes += 60;
  59.         }
  60.  
  61.         //Calcutation correction minutes to hours
  62.         if (workedMinutes > endMinutes) {
  63.             workedHours -= 1;
  64.         }
  65.  
  66.  
  67.         //Calculate days
  68.         int completeDays = 0;
  69.         if (endHour>startHour||(endHour==startHour&&endMinutes>=startMinutes)){
  70.             completeDays = endDay-startDay;
  71.         } else if (endDay>startDay+1){
  72.             completeDays = (endDay-startDay)-1;
  73.         }
  74.  
  75.  
  76.         //Define length of Months
  77.         if (startMonth == 1) {
  78.             startMonth = 31;
  79.         } else if (startMonth == 2) {
  80.             startMonth = 28;
  81.         } else if (startMonth == 3) {
  82.             startMonth = 31;
  83.         } else if (startMonth == 4) {
  84.             startMonth = 30;
  85.         } else if (startMonth == 5) {
  86.             startMonth = 31;
  87.         } else if (startMonth == 6) {
  88.             startMonth = 30;
  89.         } else if (startMonth == 7) {
  90.             startMonth = 31;
  91.         } else if (startMonth == 8) {
  92.             startMonth = 31;
  93.         } else if (startMonth == 9) {
  94.             startMonth = 30;
  95.         } else if (startMonth == 10) {
  96.             startMonth = 31;
  97.         } else if (startMonth == 11) {
  98.             startMonth = 30;
  99.         } else if (startMonth == 12) {
  100.             startMonth = 31;
  101.         }
  102.  
  103.         //Correction count of days
  104.         if (endHour>startHour||(endHour==startHour&&endMinutes>=startMinutes)){
  105.             completeDays = endDay-startDay;
  106.         } else if (endDay>startDay+1){
  107.             completeDays = (endDay-startDay);
  108.         }
  109.  
  110.         //Add days to worktime
  111.         workedHours += (completeDays * 24);
  112.  
  113.  
  114.         //Calculate sum of minutes
  115.         double completeMinutes = (workedHours * 60) + workedMinutes;
  116.  
  117.  
  118.         //Get worked time of employee
  119.         System.out.println(name + " has worked for " + workedHours + " hours and " + workedMinutes + " minutes . ");
  120.  
  121.  
  122.         //Calculate salary
  123.         double salary = (completeMinutes / 60) * 11.5;
  124.  
  125.  
  126.  
  127.         //Calculate weekend bonus
  128.         //Worked from saturday ...
  129.         if (startDayName.equalsIgnoreCase(sat)) {
  130.  
  131.  
  132.             //Saturday only
  133.             if (endDayName.equalsIgnoreCase(sat)) {
  134.  
  135.                 //Calculate work bonus Saturday only
  136.                 double bonus = salary / 4;
  137.                 System.out.println(name + "'s salary is " + (salary + bonus) + " €. ");
  138.  
  139.  
  140.                 //Saturday till sunday
  141.             } else if (endDayName.equalsIgnoreCase(sun)) {
  142.  
  143.                 //Calculate work bonus Saturday till midnight
  144.                 double bonusSat = (24 - startHour - (startMinutes / 60)) * 11.50 / 4;
  145.  
  146.                 //Calculate work bonus midnight till sunday
  147.                 double bonusSun = (endHour + (endMinutes / 60)) * 11.50 / 2;
  148.  
  149.                 System.out.println(name + "'s salary is " + (salary + bonusSat + bonusSun) + " €. ");
  150.  
  151.  
  152.                 //Saturday till another day
  153.             } else if (!endDayName.equalsIgnoreCase(sun)) {
  154.  
  155.                 //Calculate work bonus Saturday till midnight
  156.                 double bonusSat = (24 - startHour - (startMinutes / 60)) * 11.50 / 4;
  157.  
  158.                 //Add work bonus sunday complete day
  159.                 double bonusSun = 24 * 11.5 / 2;
  160.  
  161.                 System.out.println(name + "'s salary is " + (salary + bonusSat + bonusSun) + " €. ");
  162.             }
  163.  
  164.  
  165.             //Worked from sunday ...
  166.         } else if (startDayName.equalsIgnoreCase(sun)) {
  167.  
  168.  
  169.             //Sunday only
  170.             if (endDayName.equalsIgnoreCase(sun)) {
  171.  
  172.                 //Calculate work bonus Sunday only
  173.                 double bonus = salary / 2;
  174.                 System.out.println(salary + bonus);
  175.  
  176.                 System.out.println(name + "'s salary is " + (salary + bonus) + " €. ");
  177.  
  178.  
  179.                 //Sunday till another day
  180.             } else if (!endDayName.equalsIgnoreCase(sun)){
  181.  
  182.                 //Calculate work bonus Sunday till midnight
  183.                 double bonus = (24 - startHour - (startMinutes / 60)) * 11.50 / 2;
  184.  
  185.                 System.out.println(name + "'s salary is " + (salary + bonus) + " €. ");
  186.             }
  187.  
  188.  
  189.  
  190.             //Worked from any other day ...
  191.         } else if (!startDayName.equalsIgnoreCase(sun)){
  192.  
  193.  
  194.             //... till Saturday
  195.             if (endDayName.equalsIgnoreCase(sat)) {
  196.  
  197.                 //Calculate work bonus for Saturday
  198.                 double bonus = (endHour + (endMinutes / 60)) * 11.50 / 4;
  199.  
  200.                 System.out.println(name + "'s salary is " + (salary + bonus) + " €. ");
  201.  
  202.  
  203.                 //... till Sunday
  204.             } else if (endDayName.equalsIgnoreCase(sun)){
  205.  
  206.                 //Calculate work bonus for Sunday
  207.                 double bonusSun = (endHour + (endMinutes / 60)) * 11.50 / 2;
  208.  
  209.                 //Add work bonus Saturday complete day
  210.                 double bonusSat = 24 * 11.5 / 4;
  211.  
  212.                 System.out.println(name + "'s salary is " + (salary + bonusSat + bonusSun) + " €. ");
  213.             }
  214.         }
  215.  
  216.         kbd.close();
  217.     }
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement