Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package huiswerk_brasserie_koekoek;
- import java.util.Scanner;
- public class calculateTimePart1 {
- public static void main(String[] args) {
- Scanner kbd = new Scanner(System.in);
- //Ask name
- System.out.println("Name employee: ");
- String name = kbd.next();
- //Ask starting time in right format
- System.out.println("Enter starting time (hh mm): ");
- int startHour = kbd.nextInt();
- int startMinutes = 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;
- }
- //Get worked time of person
- System.out.println(name + " has worked for " + workedHours + " hours and " + workedMinutes + " minutes . ");
- kbd.close()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement