Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. package huiswerk_brasserie_koekoek;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class test {
  6. public static void main(String[] args) {
  7.  
  8. Scanner kbd = new Scanner(System.in);
  9.  
  10. //Ask starting date in the right format
  11. System.out.println("Enter starting date (dd mm)");
  12. int startDay = kbd.nextInt();
  13. int startMonth = kbd.nextInt();
  14.  
  15. //Ask starting time in the right format
  16. System.out.println("Enter starting time (hh mm): ");
  17. int startHour = kbd.nextInt();
  18. int startMinutes = kbd.nextInt();
  19.  
  20. //Ask ending date in the right format
  21. System.out.println("Enter ending date (dd mm)");
  22. int endDay = kbd.nextInt();
  23. int endMonth = kbd.nextInt();
  24.  
  25. //Ask ending time in right format
  26. System.out.println("Enter ending time (hh mm): ");
  27. int endHour = kbd.nextInt();
  28. int endMinutes = kbd.nextInt();
  29.  
  30.  
  31. //Calculate hours
  32. int workedHours = endHour - startHour;
  33. if (workedHours < 0) {
  34. workedHours += 24;
  35. }
  36.  
  37. //Calculate minutes
  38. int workedMinutes = endMinutes - startMinutes;
  39. if (workedMinutes < 0) {
  40. workedMinutes += 60;
  41. }
  42.  
  43. //Calcutation correction minutes to hours
  44. if (workedMinutes > endMinutes) {
  45. workedHours -= 1;
  46. }
  47.  
  48.  
  49. //Calculate days
  50. int completeDays = endDay - startDay;
  51.  
  52. //Define length of Months
  53. if (startMonth == 1) {
  54. startMonth = 31;
  55. } else if (startMonth == 2) {
  56. startMonth = 28;
  57. } else if (startMonth == 3) {
  58. startMonth = 31;
  59. } else if (startMonth == 4) {
  60. startMonth = 30;
  61. } else if (startMonth == 5) {
  62. startMonth = 31;
  63. } else if (startMonth == 6) {
  64. startMonth = 30;
  65. } else if (startMonth == 7) {
  66. startMonth = 31;
  67. } else if (startMonth == 8) {
  68. startMonth = 31;
  69. } else if (startMonth == 9) {
  70. startMonth = 30;
  71. } else if (startMonth == 10) {
  72. startMonth = 31;
  73. } else if (startMonth == 11) {
  74. startMonth = 30;
  75. } else if (startMonth == 12) {
  76. startMonth = 31;
  77. }
  78.  
  79. //Correction count of days
  80. if (endHour>startHour||(endHour==startHour&&endMinutes>=startMinutes)){
  81. completeDays = endDay-startDay;
  82. } else if (endDay>startDay+1){
  83. completeDays = (endDay-startDay);
  84. }
  85.  
  86.  
  87. //Add days to worktime
  88. workedHours += (completeDays * 24);
  89.  
  90.  
  91. //Calculate sum of minutes
  92. double completeMinutes = (workedHours * 60) + workedMinutes;
  93.  
  94.  
  95. //Get worked time of employee
  96. System.out.println(workedHours + " hours and " + workedMinutes + " minutes . ");
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement