引用:
作者傳說
一、沒import相關的package?
NetBean:按Alt+Shift+F
Eclipse:按Ctrl+Shift+O
不同版本可能有不同的組合鍵!
二、你要問自己那個資料陣列怎麼來的!
|
謝謝您的回答。
一、我把Jason Ju網友的程式碼放到eclipse中,如下,錯誤不少,不知該如何解決。
方便的話,可以給我全部的程式碼嗎?感恩!
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class day3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
double[] dayHoursArry = { 6.5, 9, 6.5, 9.5, 6.5, 6.5, 0, 6.5, 6.5, 6.5, 6,
9.5, 6.5, 0, 6.5, 9, 6.5, 6, 6.5, 0, 6.5, 6.5, 6.5, 6.5, 6.5,
6.5, 0, 6.5, 0, 0, 0 };
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 ");
}
}
}
}
}
二、要從資料庫去讀取,還在研究中。
