Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class DieterTest {
- public static void main(String[] args) {
- Scanner kbd = new Scanner(System.in);
- String sat = "Saturday";
- String sun = "Sunday";
- //Ask name
- System.out.println("Name employee: ");
- String name = kbd.next();
- //Ask startday
- System.out.println("Enter day (...day)");
- String startDayName = kbd.next();
- //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 endday
- System.out.println("Enter day (...day)");
- String endDayName = kbd.next();
- //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;
- } else if(endMinutes<startMinutes&&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 = 0;
- if (endHour>startHour||(endHour==startHour&&endMinutes>=startMinutes)){
- completeDays = endDay-startDay;
- } else if (endDay>startDay+1){
- completeDays = (endDay-startDay)-1;
- }
- //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(name + " has worked for " + workedHours + " hours and " + workedMinutes + " minutes . ");
- //Calculate salary
- double salary = (completeMinutes / 60) * 11.5;
- //Calculate weekend bonus
- //Worked from saturday ...
- if (startDayName.equalsIgnoreCase(sat)) {
- //Saturday only
- if (endDayName.equalsIgnoreCase(sat)) {
- //Calculate work bonus Saturday only
- double bonus = salary / 4;
- System.out.println(name + "'s salary is " + (salary + bonus) + " €. ");
- //Saturday till sunday
- } else if (endDayName.equalsIgnoreCase(sun)) {
- //Calculate work bonus Saturday till midnight
- double bonusSat = (24 - startHour - (startMinutes / 60)) * 11.50 / 4;
- //Calculate work bonus midnight till sunday
- double bonusSun = (endHour + (endMinutes / 60)) * 11.50 / 2;
- System.out.println(name + "'s salary is " + (salary + bonusSat + bonusSun) + " €. ");
- //Saturday till another day
- } else if (!endDayName.equalsIgnoreCase(sun)) {
- //Calculate work bonus Saturday till midnight
- double bonusSat = (24 - startHour - (startMinutes / 60)) * 11.50 / 4;
- //Add work bonus sunday complete day
- double bonusSun = 24 * 11.5 / 2;
- System.out.println(name + "'s salary is " + (salary + bonusSat + bonusSun) + " €. ");
- }
- //Worked from sunday ...
- } else if (startDayName.equalsIgnoreCase(sun)) {
- //Sunday only
- if (endDayName.equalsIgnoreCase(sun)) {
- //Calculate work bonus Sunday only
- double bonus = salary / 2;
- System.out.println(salary + bonus);
- System.out.println(name + "'s salary is " + (salary + bonus) + " €. ");
- //Sunday till another day
- } else if (!endDayName.equalsIgnoreCase(sun)){
- //Calculate work bonus Sunday till midnight
- double bonus = (24 - startHour - (startMinutes / 60)) * 11.50 / 2;
- System.out.println(name + "'s salary is " + (salary + bonus) + " €. ");
- }
- //Worked from any other day ...
- } else if (!startDayName.equalsIgnoreCase(sun)){
- //... till Saturday
- if (endDayName.equalsIgnoreCase(sat)) {
- //Calculate work bonus for Saturday
- double bonus = (endHour + (endMinutes / 60)) * 11.50 / 4;
- System.out.println(name + "'s salary is " + (salary + bonus) + " €. ");
- //... till Sunday
- } else if (endDayName.equalsIgnoreCase(sun)){
- //Calculate work bonus for Sunday
- double bonusSun = (endHour + (endMinutes / 60)) * 11.50 / 2;
- //Add work bonus Saturday complete day
- double bonusSat = 24 * 11.5 / 4;
- System.out.println(name + "'s salary is " + (salary + bonusSat + bonusSun) + " €. ");
- }
- }
- kbd.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement