Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package huiswerk_brasserie_koekoek;
- import java.util.Scanner;
- public class test {
- public static void main(String[] args) {
- Scanner kbd = new Scanner(System.in);
- //Ask starting date in the right format
- System.out.println("Enter starting date (dd mm)");
- int startDay = kbd.nextInt();
- int startMonth = kbd.nextInt();
- //Ask starting time in the right format
- System.out.println("Enter starting time (hh mm): ");
- int startHour = kbd.nextInt();
- int startMinutes = kbd.nextInt();
- //Ask ending date in the right format
- System.out.println("Enter ending date (dd mm)");
- int endDay = kbd.nextInt();
- int endMonth = kbd.nextInt();
- //Ask ending time in right format
- System.out.println("Enter ending time (hh mm): ");
- int endHour = kbd.nextInt();
- int endMinutes = kbd.nextInt();
- //Calculate hours
- int workedHours = endHour - startHour;
- if (workedHours < 0) {
- workedHours += 24;
- }
- //Calculate minutes
- int workedMinutes = endMinutes - startMinutes;
- if (workedMinutes < 0) {
- workedMinutes += 60;
- }
- //Calcutation correction minutes to hours
- if (workedMinutes > endMinutes) {
- workedHours -= 1;
- }
- //Calculate days
- int completeDays = endDay - startDay;
- //Define length of Months
- if (startMonth == 1) {
- startMonth = 31;
- } else if (startMonth == 2) {
- startMonth = 28;
- } else if (startMonth == 3) {
- startMonth = 31;
- } else if (startMonth == 4) {
- startMonth = 30;
- } else if (startMonth == 5) {
- startMonth = 31;
- } else if (startMonth == 6) {
- startMonth = 30;
- } else if (startMonth == 7) {
- startMonth = 31;
- } else if (startMonth == 8) {
- startMonth = 31;
- } else if (startMonth == 9) {
- startMonth = 30;
- } else if (startMonth == 10) {
- startMonth = 31;
- } else if (startMonth == 11) {
- startMonth = 30;
- } else if (startMonth == 12) {
- startMonth = 31;
- }
- //Correction count of days
- if (endHour>startHour||(endHour==startHour&&endMinutes>=startMinutes)){
- completeDays = endDay-startDay;
- } else if (endDay>startDay+1){
- completeDays = (endDay-startDay);
- }
- //Add days to worktime
- workedHours += (completeDays * 24);
- //Calculate sum of minutes
- double completeMinutes = (workedHours * 60) + workedMinutes;
- //Get worked time of employee
- System.out.println(workedHours + " hours and " + workedMinutes + " minutes . ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement