Skip to content

Commit e01d178

Browse files
author
yangzhm
committed
add project of payment
1 parent 82c7cd3 commit e01d178

21 files changed

+413
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package Affiliation;
2+
3+
import PayCheck.PayCheck;
4+
5+
public abstract class Affiliation {
6+
public abstract double calculateDeduction(PayCheck pc);
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package Affiliation;
2+
3+
import PayCheck.PayCheck;
4+
5+
public class NonAffiliation extends Affiliation{
6+
7+
@Override
8+
public double calculateDeduction(PayCheck pc) {
9+
return 0.0;
10+
}
11+
12+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package Affiliation;
2+
3+
import java.util.Date;
4+
5+
public class ServiceCharge {
6+
private Date date;
7+
private double amount;
8+
public double getAmount() {
9+
return amount;
10+
}
11+
public void setAmount(double amount) {
12+
this.amount = amount;
13+
}
14+
public Date getDate() {
15+
return date;
16+
}
17+
public void setDate(Date date) {
18+
this.date = date;
19+
}
20+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package Affiliation;
2+
3+
import java.util.Date;
4+
import java.util.Map;
5+
6+
import PayCheck.PayCheck;
7+
import DateUtil.DateUtil;
8+
9+
public class UnionAffiliation extends Affiliation{
10+
private String memId;
11+
private double weeklyDue;
12+
private Map<Date, ServiceCharge> serviceCharges;
13+
@Override
14+
public double calculateDeduction(PayCheck pc) {
15+
int fridays = DateUtil.getFridays(pc.getPayPeriodStartDate(), pc.getPayPeriodEndDate());
16+
double totalDue = fridays*this.weeklyDue;
17+
18+
double totalCharges = 0.0;
19+
for (ServiceCharge sc : serviceCharges.values()) {
20+
if (DateUtil.between(sc.getDate(), pc.getPayPeriodStartDate(), pc.getPayPeriodEndDate())) {
21+
totalCharges += sc.getAmount();
22+
}
23+
}
24+
return totalDue+totalCharges;
25+
}
26+
27+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package DateUtil;
2+
3+
import java.util.Date;
4+
5+
public class DateUtil {
6+
public static boolean isFriday(Date d) {
7+
return true;
8+
}
9+
10+
public static Date add(Date d, int days) {
11+
return new Date();
12+
}
13+
14+
public static boolean isLastDayofMonth(Date d) {
15+
return false;
16+
}
17+
18+
public static Date getFirstDay(Date d) {
19+
return new Date();
20+
}
21+
22+
public static long getDaysBetween(Date start, Date end) {
23+
return 0;
24+
}
25+
26+
public static Date parseDay(String dayStr) {
27+
return new Date();
28+
}
29+
30+
public static boolean between(Date d, Date start, Date end) {
31+
return true;
32+
}
33+
34+
public static int getFridays(Date start, Date end) {
35+
return 0;
36+
}
37+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package Employ;
2+
3+
import java.util.Date;
4+
5+
import Affiliation.Affiliation;
6+
import PayCheck.PayCheck;
7+
import PaymentClassification.PaymentClassification;
8+
import PaymentMethod.PaymentMethod;
9+
import PaymentSchedule.PaymentSchedule;
10+
11+
public class Employee {
12+
private String id;
13+
private String name;
14+
private String address;
15+
PaymentClassification payment;
16+
PaymentSchedule paySch;
17+
PaymentMethod payMethod;
18+
Affiliation af;
19+
20+
public Employee(String name, String address) {
21+
this.name = name;
22+
this.address = address;
23+
}
24+
public boolean isPayDay(Date d) {
25+
return this.paySch.isPayDay(d);
26+
}
27+
28+
public Date getPayPeriodStartDate(Date d) {
29+
return this.paySch.getPayPeriodStartDate(d);
30+
}
31+
32+
public void payDay(PayCheck pc) {
33+
double grossPay = payment.calculatePay(pc);
34+
double dedutions = af.calculateDeduction(pc);
35+
double netPay = grossPay - dedutions;
36+
pc.setGrossPay(grossPay);
37+
pc.setDeductions(dedutions);
38+
pc.setNetPay(netPay);
39+
payMethod.pay(pc);
40+
}
41+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package PayCheck;
2+
3+
import java.util.Date;
4+
5+
public class PayCheck {
6+
private int payPeriodStart;
7+
private int payPeriodEnd;
8+
private double grossPay;
9+
private double deductions;
10+
private double netPay;
11+
public double getGrossPay() {
12+
return grossPay;
13+
}
14+
public void setGrossPay(double grossPay) {
15+
this.grossPay = grossPay;
16+
}
17+
public double getDeductions() {
18+
return deductions;
19+
}
20+
public void setDeductions(double deductions) {
21+
this.deductions = deductions;
22+
}
23+
public double getNetPay() {
24+
return netPay;
25+
}
26+
public void setNetPay(double netPay) {
27+
this.netPay = netPay;
28+
}
29+
30+
public Date getPayPeriodStartDate() {
31+
return new Date();
32+
}
33+
public Date getPayPeriodEndDate() {
34+
return new Date();
35+
}
36+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package PaymentClassification;
2+
3+
import java.util.Date;
4+
import java.util.Map;
5+
6+
import PayCheck.PayCheck;
7+
import DateUtil.DateUtil;
8+
9+
public class CommissionClassification extends PaymentClassification{
10+
private double rate = 0.0;
11+
private double salary = 0.0;
12+
private Map<Date, SalesReceipt> receipts;
13+
@Override
14+
public double calculatePay(PayCheck pc) {
15+
double commission = 0.0;
16+
for (SalesReceipt sr : receipts.values()) {
17+
if (DateUtil.between(sr.getDate(), pc.getPayPeriodStartDate(), pc.getPayPeriodEndDate())) {
18+
commission += sr.getAmount()*rate;
19+
}
20+
}
21+
return commission+salary;
22+
}
23+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package PaymentClassification;
2+
3+
import java.util.Date;
4+
import java.util.Map;
5+
6+
import DateUtil.DateUtil;
7+
import PayCheck.PayCheck;
8+
9+
public class HourlyClassification extends PaymentClassification{
10+
private double hourlyRate = 0.0;
11+
private Map<Date, TimeCard> timeCards;
12+
13+
public void addTimeCard(TimeCard tc) {
14+
timeCards.put(tc.getDate(), tc);
15+
}
16+
17+
@Override
18+
public double calculatePay(PayCheck pc) {
19+
double total = 0.0;
20+
21+
for (TimeCard tc : timeCards.values()) {
22+
if (DateUtil.between(tc.getDate(), pc.getPayPeriodStartDate(), pc.getPayPeriodEndDate())) {
23+
total += calculatePayForTimeCard(tc);
24+
}
25+
}
26+
27+
return total;
28+
}
29+
30+
private double calculatePayForTimeCard(TimeCard tc) {
31+
int hours = tc.getHours();
32+
if (hours > 8) {
33+
return 8*this.hourlyRate + (hours - 8)*this.hourlyRate*1.5;
34+
} else {
35+
return 8*this.hourlyRate;
36+
}
37+
}
38+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package PaymentClassification;
2+
3+
import PayCheck.PayCheck;
4+
5+
public abstract class PaymentClassification {
6+
public abstract double calculatePay(PayCheck pc);
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package PaymentClassification;
2+
3+
import PayCheck.PayCheck;
4+
5+
public class SalariedClassification extends PaymentClassification {
6+
private double salary = 0.0;
7+
8+
@Override
9+
public double calculatePay(PayCheck pc) {
10+
return salary;
11+
}
12+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package PaymentClassification;
2+
3+
import java.util.Date;
4+
5+
public class SalesReceipt {
6+
private Date date;
7+
private double amount;
8+
public Date getDate() {
9+
return date;
10+
}
11+
public void setDate(Date date) {
12+
this.date = date;
13+
}
14+
public double getAmount() {
15+
return amount;
16+
}
17+
public void setAmount(double amount) {
18+
this.amount = amount;
19+
}
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package PaymentClassification;
2+
3+
import java.util.Date;
4+
5+
public class TimeCard {
6+
private Date date;
7+
private int startTime;
8+
private int endTime;
9+
10+
public Date getDate() {
11+
return date;
12+
}
13+
public void setDate(Date date) {
14+
this.date = date;
15+
}
16+
17+
public int getHours() {
18+
return endTime - startTime;
19+
}
20+
21+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package PaymentMethod;
2+
3+
import PayCheck.PayCheck;
4+
5+
public class BankMethod extends PaymentMethod{
6+
private String bank;
7+
private double account;
8+
@Override
9+
public void pay(PayCheck pc) {
10+
// TODO Auto-generated method stub
11+
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package PaymentMethod;
2+
3+
import PayCheck.PayCheck;
4+
5+
public class HoldMethod extends PaymentMethod{
6+
7+
@Override
8+
public void pay(PayCheck pc) {
9+
// TODO Auto-generated method stub
10+
11+
}
12+
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package PaymentMethod;
2+
3+
import PayCheck.PayCheck;
4+
5+
public class MailMethod extends PaymentMethod{
6+
private String address;
7+
8+
@Override
9+
public void pay(PayCheck pc) {
10+
// TODO Auto-generated method stub
11+
12+
}
13+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package PaymentMethod;
2+
3+
import PayCheck.PayCheck;
4+
5+
public abstract class PaymentMethod {
6+
public abstract void pay(PayCheck pc);
7+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package PaymentSchedule;
2+
3+
import java.util.Date;
4+
import DateUtil.DateUtil;
5+
6+
public class BiWeeklySchedule implements PaymentSchedule{
7+
Date firstFriday = DateUtil.parseDay("2017-01-01");
8+
@Override
9+
public boolean isPayDay(Date date) {
10+
long interval = DateUtil.getDaysBetween(firstFriday, date);
11+
return interval%14 == 0;
12+
}
13+
14+
@Override
15+
public Date getPayPeriodStartDate(Date date) {
16+
return DateUtil.add(date, -13);
17+
}
18+
19+
}

0 commit comments

Comments
 (0)