瀏覽單個文章
Jason Ju
Regular Member
 

加入日期: Mar 2000
您的住址: Taiwan
文章: 78
代碼:
public void count(final double[] dayHoursArry){
	for(int i = 0; i < dayHoursArry.length; i ++){
		final int startDate = i;
		//三、7天內的工時合計不可超過48小時
		final int weekEndDate = i+6; 
		final double[] newArry7days = Arrays.copyOfRange(dayHoursArry, startDate, weekEndDate);
		final double weekdayHours = getSum(newArry7days);
		System.out.println("day " + startDate + " to day " + weekEndDate + " hours = " + weekdayHours);
		chekcOffDays(newArry7days);
		if(weekdayHours > 48) {
			System.out.println(" ==> over " + (weekdayHours-48) );
		}
		//四、14天內的工時合計不可超過80小時,若超過時顯示加班幾個小時
		final int twoWeekEndDate = i+13;
		final double[] newArry14days = Arrays.copyOfRange(dayHoursArry, startDate, twoWeekEndDate);
		final double twoWeekdayHours = getSum(newArry14days);
		System.out.println("day " + startDate + " to day " + twoWeekEndDate + " hours = " + twoWeekdayHours);
		chekcOffDays(newArry14days);
		if(twoWeekdayHours > 80){ 
			System.out.println(" ==> over " + (twoWeekdayHours-80) );
		}
	}
}

public double getSum(final double[] arry){
	double sum = 0;
	for(double d: arry) sum +=d; 
	return sum;
}


public static void chekcOffDays(final double[] array) { 
	//一、7休1
	if(array.length == 7 && !Arrays.asList(array).contains(0))
		System.out.println("7天未休1 ");			
	//二、14休2
	if(array.length == 14){
		if(Arrays.asList(array).contains(0)){
			Set dupes = new HashSet(); 
			for (double d : array) {
				if(d == 0 && !dupes.add(d))
					break;
				System.out.println("14天僅休1 ");		
			} 
		}else {
			System.out.println("14天未休2 ");	
		}
	} 
}
舊 2016-12-26, 10:55 AM #25
回應時引用此文章
Jason Ju離線中