打卡上班

package demo.java.date;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;

// 日付
public class AttendanceDate {
    private List<Person> Persons = new ArrayList<>();
    private LocalDate localDate;

    public List<Person> getPersons() {
        return Persons;
    }

    public void setPersons(Person person) {
        Persons.add(person);
    }

    public LocalDate getLocalDate() {
        return localDate;
    }

    public AttendanceDate(LocalDate localDate) {
        this.localDate = localDate;
    }
}
package demo.java.date;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

public class AttendanceManagement {
    List<AttendanceDate> dates = new ArrayList<>();

    public List<AttendanceDate> getDates() {
        return dates;
    }

    public void setDates(AttendanceDate date) {
        this.dates.add(date);
    }
}
package demo.java.date;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Random;

public class Client {
    public static void main(String[] args) {

        // 勤務記録仕組み
        AttendanceManagement ams = new AttendanceManagement();
        // 社員作成(初期値作成)
        Person p = new Person("");
        // 勤務日付(初期値作成)
        LocalDate localDate = LocalDate.now();
        // 時間登録(初期値作成)
        LocalDateTime tempTime = LocalDateTime.now();
        for (int j=0; j<10;j++) {
            // 勤務日付登録する
            int day = 1 + j;
            localDate = LocalDate.of(2021, 4, day);
            // 勤務日付登録
            AttendanceDate ad = new AttendanceDate(localDate);
            for (int n=0;n<10;n++) {
                // 勤務対象者登録
                p = new Person("wang" + n);
                int startHour = new Random().nextInt(8);
                for(int i=0;i<10;i++) {
                    // 勤務時間作成
                    int hour = startHour + i;
                    int minute = 0 + n;
                    tempTime = LocalDateTime.of(localDate.getYear(), localDate.getMonth(), localDate.getDayOfMonth(), hour, minute);
                    // 勤務記録する
                    // 8時前、17時以降は勤務とならない
                    if (tempTime.getHour() >= 8 && tempTime.getHour() <= 17) {
                        p.setLocalTimes(tempTime.toLocalTime());
                    }
                }
                ad.setPersons(p);
            }
            // 勤務日付を登録
            ams.setDates(ad);
        }

        // 勤務リスト表示
        long minHour = Long.MAX_VALUE;
        for (AttendanceDate item : ams.getDates()) {
            System.out.println(item.getLocalDate().toString() + "の勤怠状況:");
            for (Person person : item.getPersons()) {
                System.out.println("  " + person);
                Duration duration = Duration.between(person.getLocalTimes().get(0), person.getLocalTimes().get(person.getLocalTimes().size() -1));
                if (duration.toHours() < minHour) {
                    minHour = duration.toHours();
                }
                System.out.println("    本日の勤務時間:" + duration.toHours());
            }
            System.out.println("  本日の最短勤務時間は:" + minHour + "\n");
        }

    }
}
package demo.java.date;

import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;

public class Person {
    // 名前
    private String name;
    // 時間
    private List<LocalTime> localTimes = new ArrayList<>();

    public List<LocalTime> getLocalTimes() {
        return localTimes;
    }

    public void setLocalTimes(LocalTime localTime) {
        this.localTimes.add(localTime);
    }

    public String getName() {
        return name;
    }

    public Person(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append("社員:");
        sb.append(name);
        sb.append(" 時間記録:");
        for (LocalTime localTime : getLocalTimes()) {
            sb.append("[");
            sb.append(localTime.toString());
            sb.append("]");
        }
        return sb.toString();
    }
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值