diff --git a/dicegame.png b/dicegame.png deleted file mode 100644 index 1c1a40821a..0000000000 Binary files a/dicegame.png and /dev/null differ diff --git a/liuxin/ood/ood-assignment/src/main/java/com/coderising/dp/builder/TagNode.java b/liuxin/ood/ood-assignment/src/main/java/com/coderising/dp/builder/TagNode.java index 7763ee9d0a..2ac26ad7b9 100644 --- a/liuxin/ood/ood-assignment/src/main/java/com/coderising/dp/builder/TagNode.java +++ b/liuxin/ood/ood-assignment/src/main/java/com/coderising/dp/builder/TagNode.java @@ -19,6 +19,7 @@ public void setAttribute(String name, String value) { Attribute attr = findAttribute(name); if(attr != null){ attr.value = value; + return; } attributes.add(new Attribute(name,value)); diff --git a/shopping.png b/shopping.png deleted file mode 100644 index 6ef672f5f9..0000000000 Binary files a/shopping.png and /dev/null differ diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/Affiliation.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/Affiliation.java new file mode 100644 index 0000000000..091165a2af --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/Affiliation.java @@ -0,0 +1,5 @@ +package com.coderising.payroll; + +public interface Affiliation { + public double calculateDeductions(Paycheck pc); +} diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/BankMethod.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/BankMethod.java new file mode 100644 index 0000000000..a7b0dd9436 --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/BankMethod.java @@ -0,0 +1,8 @@ +package com.coderising.payroll; + +public class BankMethod implements PaymentMethod{ + private String account; + public void pay(Paycheck pc){ + System.out.println("转到银行账号:"+account+"。备注:"+pc); + } +} diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/BiWeeklySchedule.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/BiWeeklySchedule.java new file mode 100644 index 0000000000..943b4ae757 --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/BiWeeklySchedule.java @@ -0,0 +1,18 @@ +package com.coderising.payroll; + +import java.util.Date; + +public class BiWeeklySchedule implements PaymentSchedule{ + private Date firstPayDay; + public BiWeeklySchedule(String firstPayDay){ + this.firstPayDay = DateUtil.parseDate(firstPayDay); + } + + public boolean isPayDate(Date date){ + return DateUtil.getDaysBetween(firstPayDay, date)%14 == 0; + } + + public Date getPayPeriodStartDate( Date payPeriodEndDate){ + return DateUtil.add(payPeriodEndDate, -13); + } +} diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/ComissionClassification.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/ComissionClassification.java new file mode 100644 index 0000000000..e8ef651b11 --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/ComissionClassification.java @@ -0,0 +1,28 @@ +package com.coderising.payroll; + +import java.util.ArrayList; +import java.util.List; + +public class ComissionClassification implements PaymentClassification { + private double salary; + private double rate; + List receipts = new ArrayList<>(); + + public ComissionClassification(double salary, double rate, List receipts) { + super(); + this.salary = salary; + this.rate = rate; + this.receipts = receipts; + } + + + public double calculatePay(Paycheck pc){ + double totalAmount = 0.0; + for(SalesReceipt sr:receipts){ + if(DateUtil.between(sr.getSaleDate(),pc.getPayPeriodStartDate(), pc.getPayPeriodEndDate())){ + totalAmount += sr.getAmount(); + } + } + return salary + totalAmount*rate; + } +} diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/DateUtil.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/DateUtil.java new file mode 100644 index 0000000000..0b2c6aad54 --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/DateUtil.java @@ -0,0 +1,99 @@ +package com.coderising.payroll; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; + +public class DateUtil { + public static final long SECOND_IN_MS = 1000L; + public static final long MINUTE_IN_S = 60L; + public static final long HOUR_IN_MINUTE = 60L; + public static final long DAY_IN_HOUR = 24L; + public static final long DAY_IN_MS = DAY_IN_HOUR*HOUR_IN_MINUTE*MINUTE_IN_S*SECOND_IN_MS; + private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + + public static boolean isFriday(Date date){ + Calendar calendar = new GregorianCalendar(); + calendar.setTime(date); + return calendar.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY; + } + + public static int getDaysBetween(Date beginDate, Date endDate){ + assert(endDate.after(beginDate)); + return (int)((endDate.getTime() - beginDate.getTime())/DAY_IN_MS); + } + + public static Date parseDate(String strDate){ + try{ + return sdf.parse(strDate); + } + catch(ParseException e){ + throw new RuntimeException(e); + } + } + + public static Date add(Date date, int dayCount){ + Calendar calendar = new GregorianCalendar(); + calendar.setTime(date); + calendar.add(Calendar.DATE, dayCount); + return calendar.getTime(); + } + + /** + * 判断当前日期是否是当月最后一个工作日 + * true: 当前日期是工作日并且与下一工作日不同月 + * */ + public static boolean isLastWorkDayOfMonth(Date d){ + if(isWeekday(d)){ + Date nextWeekday = nextWeekday(d); + Calendar calendar = new GregorianCalendar(); + calendar.setTime(d); + int mouth = calendar.get(Calendar.MONTH); + calendar.setTime(nextWeekday); + return mouth != calendar.get(Calendar.MONTH); + } + return false; + } + + public static boolean isWeekday(Date d){ + Calendar calendar = new GregorianCalendar(); + calendar.setTime(d); + int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); + return Calendar.MONDAY <= dayOfWeek && dayOfWeek <= Calendar.FRIDAY; + } + + public static Date nextWeekday(Date d){ + Calendar calendar = new GregorianCalendar(); + calendar.setTime(d); + int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); + switch (dayOfWeek) { + case Calendar.FRIDAY: + calendar.add(Calendar.DATE, 3); + break; + case Calendar.SATURDAY: + calendar.add(Calendar.DATE, 2); + break; + default: + calendar.add(Calendar.DATE, 1); + break; + } + return calendar.getTime(); + } + + public static Date getFirstDayOfMonth(Date d){ + Calendar calendar = new GregorianCalendar(); + calendar.setTime(d); + calendar.set(Calendar.DAY_OF_MONTH, 1); + return calendar.getTime(); + } + + public static boolean between(Date d, Date startDate, Date endDate){ + return d.compareTo(startDate)>=0 && d.compareTo(endDate)<=0; + } + + public static String format(Date d){ + return sdf.format(d); + } +} diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/Employee.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/Employee.java new file mode 100644 index 0000000000..75fbc04ddf --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/Employee.java @@ -0,0 +1,56 @@ +package com.coderising.payroll; + +import java.util.Date; + +public class Employee { + String id; + String name; + String address; + Affiliation affiliation = new NonAffiliation(); + + + PaymentClassification classification; + PaymentSchedule schedule; + PaymentMethod paymentMethod; + + public Employee(String id, String name, String address){ + this.id = id; + this.name = name; + this.address = address; + } + public boolean isPayDay(Date d) { + return schedule.isPayDate(d); + } + + public Date getPayPeriodStartDate(Date d) { + return schedule.getPayPeriodStartDate(d); + } + + public void payDay(Paycheck pc){ + double grossPay = classification.calculatePay(pc); + double deductions = affiliation.calculateDeductions(pc); + double netPay = grossPay - deductions; + pc.setGrossPay(grossPay); + pc.setDeductions(deductions); + pc.setNetPay(netPay); + this.paymentMethod.pay(pc); + } + + public void setClassification(PaymentClassification classification) { + this.classification = classification; + } + public void setSchedule(PaymentSchedule schedule) { + this.schedule = schedule; + } + public void setPaymentMethod(PaymentMethod paymentMethod) { + this.paymentMethod = paymentMethod; + } + public void setAffiliation(Affiliation affiliation) { + this.affiliation = affiliation; + } + @Override + public String toString() { + return "Employee [id=" + id + ", name=" + name + ", address=" + address + "]"; + } +} + diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/HoldMethod.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/HoldMethod.java new file mode 100644 index 0000000000..d1f4b48a4d --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/HoldMethod.java @@ -0,0 +1,7 @@ +package com.coderising.payroll; + +public class HoldMethod implements PaymentMethod{ + public void pay(Paycheck pc){ + System.out.println("转到财务处:"+pc); + } +} diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/HourlyClassification.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/HourlyClassification.java new file mode 100644 index 0000000000..9cdce41184 --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/HourlyClassification.java @@ -0,0 +1,40 @@ +package com.coderising.payroll; + +import java.util.ArrayList; +import java.util.List; + +public class HourlyClassification implements PaymentClassification{ + private double hourlyRate; + private List timeCards = new ArrayList<>(); + + public HourlyClassification(double hourlyRate, List timeCards) { + super(); + this.hourlyRate = hourlyRate; + this.timeCards = timeCards; + } + + public double getHourlyRate() { + return hourlyRate; + } + + public void setHourlyRate(double hourlyRate) { + this.hourlyRate = hourlyRate; + } + + public double calculatePay(Paycheck pc){ + double salary = 0.0; + for(TimeCard tc:timeCards){ + if(DateUtil.between(tc.getDate(), pc.getPayPeriodStartDate(), pc.getPayPeriodEndDate())){ + salary += calculatePayForTimeCard(tc); + } + } + return salary; + } + + private double calculatePayForTimeCard(TimeCard tc){ + if(tc.getHours() > 8){ + return 8*hourlyRate + (tc.getHours()-8)*1.5*hourlyRate; + } + return tc.getHours()*hourlyRate; + } +} diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/MailMethod.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/MailMethod.java new file mode 100644 index 0000000000..19e59fa512 --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/MailMethod.java @@ -0,0 +1,8 @@ +package com.coderising.payroll; + +public class MailMethod implements PaymentMethod{ + private String address; + public void pay(Paycheck pc){ + System.out.println("邮寄到:"+address+"。备注:"+pc); + } +} diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/MonthlySchedule.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/MonthlySchedule.java new file mode 100644 index 0000000000..86f9b7e21c --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/MonthlySchedule.java @@ -0,0 +1,13 @@ +package com.coderising.payroll; + +import java.util.Date; + +public class MonthlySchedule implements PaymentSchedule{ + public boolean isPayDate(Date date){ + return DateUtil.isLastWorkDayOfMonth(date); + } + + public Date getPayPeriodStartDate( Date payPeriodEndDate){ + return DateUtil.getFirstDayOfMonth(payPeriodEndDate); + } +} diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/NonAffiliation.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/NonAffiliation.java new file mode 100644 index 0000000000..31129fbab4 --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/NonAffiliation.java @@ -0,0 +1,7 @@ +package com.coderising.payroll; + +public class NonAffiliation implements Affiliation{ + public double calculateDeductions(Paycheck pc){ + return 0.0; + } +} diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/Paycheck.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/Paycheck.java new file mode 100644 index 0000000000..81af0d4d66 --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/Paycheck.java @@ -0,0 +1,41 @@ +package com.coderising.payroll; + +import java.util.Date; + +public class Paycheck { + private Date payPeriodStart; + private Date payPeriodEnd; + private double grossPay; + private double netPay; + private double deductions; + + public Paycheck(Date payPeriodStart, Date payPeriodEnd){ + this.payPeriodStart = payPeriodStart; + this.payPeriodEnd = payPeriodEnd; + } + public void setGrossPay(double grossPay) { + this.grossPay = grossPay; + + } + public void setDeductions(double deductions) { + this.deductions = deductions; + } + public void setNetPay(double netPay){ + this.netPay = netPay; + } + public Date getPayPeriodEndDate() { + + return this.payPeriodEnd; + } + public Date getPayPeriodStartDate() { + + return this.payPeriodStart; + } + @Override + public String toString() { + return "[开始时间=" + DateUtil.format(payPeriodStart) + ", 结束时间=" + DateUtil.format(payPeriodEnd) + ", 应发=" + + grossPay + ", 扣款=" + deductions + ", 实发=" + netPay + "]"; + } + + +} diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/PaymentClassification.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/PaymentClassification.java new file mode 100644 index 0000000000..f2bf2e26e9 --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/PaymentClassification.java @@ -0,0 +1,5 @@ +package com.coderising.payroll; + +public interface PaymentClassification { + public double calculatePay(Paycheck pc); +} diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/PaymentMethod.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/PaymentMethod.java new file mode 100644 index 0000000000..5e549916b6 --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/PaymentMethod.java @@ -0,0 +1,5 @@ +package com.coderising.payroll; + +public interface PaymentMethod { + public void pay(Paycheck pc); +} diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/PaymentSchedule.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/PaymentSchedule.java new file mode 100644 index 0000000000..500d72404d --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/PaymentSchedule.java @@ -0,0 +1,8 @@ +package com.coderising.payroll; + +import java.util.Date; + +public interface PaymentSchedule { + public boolean isPayDate(Date date); + public Date getPayPeriodStartDate( Date payPeriodEndDate); +} diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/SalariedClassification.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/SalariedClassification.java new file mode 100644 index 0000000000..d7c556405e --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/SalariedClassification.java @@ -0,0 +1,14 @@ +package com.coderising.payroll; + +public class SalariedClassification implements PaymentClassification { + private double salary; + + public SalariedClassification(double salary) { + super(); + this.salary = salary; + } + + public double calculatePay(Paycheck pc){ + return salary; + } +} diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/SalesReceipt.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/SalesReceipt.java new file mode 100644 index 0000000000..18297d3fc5 --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/SalesReceipt.java @@ -0,0 +1,21 @@ +package com.coderising.payroll; + +import java.util.Date; + +public class SalesReceipt { + private Date saleDate; + private double amount; + + + public SalesReceipt(Date saleDate, double amount) { + super(); + this.saleDate = saleDate; + this.amount = amount; + } + public Date getSaleDate() { + return saleDate; + } + public double getAmount() { + return amount; + } +} diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/TimeCard.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/TimeCard.java new file mode 100644 index 0000000000..2aadeabb48 --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/TimeCard.java @@ -0,0 +1,19 @@ +package com.coderising.payroll; + +import java.util.Date; + +public class TimeCard { + private Date date; + private int hours; + + public TimeCard(Date date, int hours){ + this.date = date; + this.hours = hours; + } + public Date getDate() { + return date; + } + public int getHours() { + return hours; + } +} diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/UnionAffiliation.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/UnionAffiliation.java new file mode 100644 index 0000000000..c9021baf0f --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/UnionAffiliation.java @@ -0,0 +1,17 @@ +package com.coderising.payroll; + +public class UnionAffiliation implements Affiliation{ + private String memberId; + private double weeklyDue; + + public UnionAffiliation(double weeklyDue) { + super(); + this.weeklyDue = weeklyDue; + } + + public double calculateDeductions(Paycheck pc){ + //简单实现 + int dayCount = DateUtil.getDaysBetween(pc.getPayPeriodStartDate(), pc.getPayPeriodEndDate()); + return (dayCount+1)/7 * weeklyDue; + } +} diff --git a/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/WeeklySchedule.java b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/WeeklySchedule.java new file mode 100644 index 0000000000..b9788bd18a --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/java/com/coderising/payroll/WeeklySchedule.java @@ -0,0 +1,12 @@ +package com.coderising.payroll; + +import java.util.Date; + +public class WeeklySchedule implements PaymentSchedule{ + public boolean isPayDate(Date date){ + return DateUtil.isFriday(date); + } + public Date getPayPeriodStartDate( Date payPeriodEndDate){ + return DateUtil.add(payPeriodEndDate, -6); + } +} diff --git a/students/282692248/ood/ood-assignment/src/main/resources/employees.txt b/students/282692248/ood/ood-assignment/src/main/resources/employees.txt new file mode 100644 index 0000000000..6f2535dd25 --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/resources/employees.txt @@ -0,0 +1,9 @@ +1 jerry china hourly 0.0 20.0 +2 tom usa hourly 0.0 30.0 +3 herry china hourly 0.0 25.0 +4 lily uk comission 1000.0 0.01 +5 merry china comission 1200.0 0.02 +6 lida japan comission 800.0 0.01 +7 kerry china salaried 5000.0 0.0 +8 jemmy japan salaried 8000.0 0.0 +9 jim usa salaried 7500.0 0.0 \ No newline at end of file diff --git a/students/282692248/ood/ood-assignment/src/main/resources/salesreceipt.txt b/students/282692248/ood/ood-assignment/src/main/resources/salesreceipt.txt new file mode 100644 index 0000000000..c9105f4a20 --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/resources/salesreceipt.txt @@ -0,0 +1,9 @@ +2017-06-30 4 3000.0 +2017-07-11 4 5000.0 +2017-07-14 4 4000.0 +2017-06-29 5 2000.0 +2017-07-02 5 3000.0 +2017-07-15 5 3000.0 +2017-07-01 6 4000.0 +2017-07-08 6 3000.0 +2017-07-16 6 2000.0 \ No newline at end of file diff --git a/students/282692248/ood/ood-assignment/src/main/resources/timecard.txt b/students/282692248/ood/ood-assignment/src/main/resources/timecard.txt new file mode 100644 index 0000000000..995a2d20d5 --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/resources/timecard.txt @@ -0,0 +1,9 @@ +2017-07-07 1 9 +2017-07-11 1 7 +2017-07-14 1 5 +2017-07-08 2 10 +2017-07-13 2 6 +2017-07-15 2 7 +2017-07-12 3 9 +2017-07-14 3 9 +2017-07-16 3 9 \ No newline at end of file diff --git a/students/282692248/ood/ood-assignment/src/main/resources/union.txt b/students/282692248/ood/ood-assignment/src/main/resources/union.txt new file mode 100644 index 0000000000..c15a30d749 --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/main/resources/union.txt @@ -0,0 +1,4 @@ +1 +5 +7 +9 \ No newline at end of file diff --git a/students/282692248/ood/ood-assignment/src/test/java/com/coderising/payroll/EmployeeTest.java b/students/282692248/ood/ood-assignment/src/test/java/com/coderising/payroll/EmployeeTest.java new file mode 100644 index 0000000000..2bd6757ae2 --- /dev/null +++ b/students/282692248/ood/ood-assignment/src/test/java/com/coderising/payroll/EmployeeTest.java @@ -0,0 +1,119 @@ +package com.coderising.payroll; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.junit.Test; + +public class EmployeeTest { + + @Test + public void test() throws Exception{ + Date d = DateUtil.parseDate("2017-07-31"); + List employeeList = loadEmployees(); + for(Employee e:employeeList){ + if(e.isPayDay(d)){ + Paycheck pc = new Paycheck(e.getPayPeriodStartDate(d), d); + System.out.println("发工资--> "+e); + e.payDay(pc); + } + } + } + + private List loadEmployees()throws Exception{ + List employees = new ArrayList<>(); + Set unioners = loadUnionIds(); + UnionAffiliation ua = new UnionAffiliation(5.0); + Map> tcMap = loadTimeCard(); + Map> srMap = loadSalyReceipt(); + String employeesFileName = "D:\\coding2017\\students\\282692248\\ood\\ood-assignment\\src\\main\\resources\\employees.txt"; + BufferedReader br = new BufferedReader(new FileReader(employeesFileName)); + String line = null;//id name address type salary rate + while( (line = br.readLine()) != null ){ + String[] fileds = line.split("\t"); + String id = fileds[0]; + Employee employee = new Employee(id,fileds[1], fileds[2]); + switch (fileds[3]) { + case "hourly": + employee.setClassification(new HourlyClassification(Double.parseDouble(fileds[5]),tcMap.get(id))); + employee.setSchedule(new WeeklySchedule()); + break; + case "comission": + employee.setClassification(new ComissionClassification(Double.parseDouble(fileds[4]), + Double.parseDouble(fileds[5]), srMap.get(id))); + employee.setSchedule(new BiWeeklySchedule("2017-05-05")); + break; + case "salaried": + employee.setClassification(new SalariedClassification(Double.parseDouble(fileds[4]))); + employee.setSchedule(new MonthlySchedule()); + break; + default: + throw new RuntimeException("unkonwn type ["+fileds[3]+"]"); + } + employee.setPaymentMethod(new HoldMethod()); + if(unioners.contains(id)){ + employee.setAffiliation(ua); + } + employees.add(employee); + } + br.close(); + return employees; + } + + private Set loadUnionIds() throws Exception{ + Set unioners = new HashSet<>(); + String unionFileName = "D:\\coding2017\\students\\282692248\\ood\\ood-assignment\\src\\main\\resources\\union.txt"; + BufferedReader br = new BufferedReader(new FileReader(unionFileName)); + String line = null; + while( (line = br.readLine()) != null ){ + unioners.add(line); + } + br.close(); + return unioners; + } + + private Map> loadTimeCard() throws Exception{ + Map> result = new HashMap<>(); + String timecardFileName = "D:\\coding2017\\students\\282692248\\ood\\ood-assignment\\src\\main\\resources\\timecard.txt"; + BufferedReader br = new BufferedReader(new FileReader(timecardFileName)); + String line = null; + while( (line = br.readLine()) != null ){//date id hours + String[] fields = line.split("\t"); + TimeCard tc = new TimeCard(DateUtil.parseDate(fields[0]),Integer.parseInt(fields[2])); + List tcList = result.get(fields[1]); + if(tcList == null){ + tcList = new ArrayList<>(); + result.put(fields[1], tcList); + } + tcList.add(tc); + } + br.close(); + return result; + } + + private Map> loadSalyReceipt() throws Exception{ + Map> result = new HashMap<>(); + String receiptFileName = "D:\\coding2017\\students\\282692248\\ood\\ood-assignment\\src\\main\\resources\\salesreceipt.txt"; + BufferedReader br = new BufferedReader(new FileReader(receiptFileName)); + String line = null; + while( (line = br.readLine()) != null ){//date id amount + String[] fields = line.split("\t"); + SalesReceipt sr = new SalesReceipt(DateUtil.parseDate(fields[0]),Double.parseDouble(fields[2])); + List srList = result.get(fields[1]); + if(srList == null){ + srList = new ArrayList<>(); + result.put(fields[1], srList); + } + srList.add(sr); + } + br.close(); + return result; + } +}