Skip to content

Commit 0a93782

Browse files
author
Paul Rayner
committed
Add sample files.
0 parents  commit 0a93782

File tree

9 files changed

+359
-0
lines changed

9 files changed

+359
-0
lines changed

src/warranty/Claim.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package warranty;
2+
3+
import java.util.ArrayList;
4+
import java.util.Date;
5+
import java.util.List;
6+
7+
public class Claim {
8+
9+
public Claim(int id, double amount, Date date) {
10+
super();
11+
this.id = id;
12+
this.amount = amount;
13+
this.date = date;
14+
}
15+
public int id;
16+
public double amount;
17+
public Date date = new Date();
18+
public List<RepairPO> repairPO = new ArrayList<RepairPO>();
19+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package warranty;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import warranty.Contract.Status;
7+
8+
public class ClaimsAdjudicationService {
9+
10+
public void Adjudicate(Contract contract, Claim newClaim) {
11+
double claimTotal = 0;
12+
List<Claim> claims = new ArrayList<Claim>();
13+
claims.addAll(contract.getClaims());
14+
15+
for (Claim claim:claims)
16+
{
17+
claimTotal += claim.amount;
18+
}
19+
20+
if (((contract.purchasePrice - claimTotal) * 0.8 > newClaim.amount) &&
21+
(newClaim.date.compareTo(contract.effectiveDate) >= 0) &&
22+
(newClaim.date.compareTo(contract.expirationDate) <= 0) &&
23+
(contract.status == Status.ACTIVE)) {
24+
contract.add(newClaim);
25+
}
26+
}
27+
}

src/warranty/ClientCompany.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package warranty;
2+
3+
public class ClientCompany {
4+
public final String name;
5+
public final String description;
6+
public final String code;
7+
8+
@Override
9+
public int hashCode() {
10+
final int prime = 31;
11+
int result = 1;
12+
result = prime * result + ((code == null) ? 0 : code.hashCode());
13+
result = prime * result
14+
+ ((description == null) ? 0 : description.hashCode());
15+
result = prime * result + ((name == null) ? 0 : name.hashCode());
16+
return result;
17+
}
18+
19+
@Override
20+
public boolean equals(Object obj) {
21+
if (this == obj)
22+
return true;
23+
if (obj == null)
24+
return false;
25+
if (getClass() != obj.getClass())
26+
return false;
27+
ClientCompany other = (ClientCompany) obj;
28+
if (code == null) {
29+
if (other.code != null)
30+
return false;
31+
} else if (!code.equals(other.code))
32+
return false;
33+
if (description == null) {
34+
if (other.description != null)
35+
return false;
36+
} else if (!description.equals(other.description))
37+
return false;
38+
if (name == null) {
39+
if (other.name != null)
40+
return false;
41+
} else if (!name.equals(other.name))
42+
return false;
43+
return true;
44+
}
45+
46+
public ClientCompany(String name, String description, String code) {
47+
super();
48+
this.name = name;
49+
this.description = description;
50+
this.code = code;
51+
}
52+
}

src/warranty/Contract.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package warranty;
2+
3+
import java.util.ArrayList;
4+
import java.util.Date;
5+
import java.util.List;
6+
7+
import warranty.Claim;
8+
9+
public class Contract {
10+
11+
public Contract(int id, double d) {
12+
this.purchasePrice = d;
13+
this.status = Status.PENDING;
14+
}
15+
16+
public int id;
17+
public double purchasePrice;
18+
public Date effectiveDate = new Date();
19+
public Date expirationDate = new Date();
20+
public Date purchaseDate = new Date();
21+
public int inStoreGuaranteeDays;
22+
public Status status;
23+
public Product product;
24+
25+
public enum Status { PENDING, ACTIVE, EXPIRED }
26+
27+
private List<Claim> Claims = new ArrayList<Claim>();
28+
29+
public void add(Claim Claim)
30+
{
31+
Claims.add(Claim);
32+
}
33+
34+
public List<Claim> getClaims()
35+
{
36+
return Claims;
37+
}
38+
39+
public void remove(Claim Claim)
40+
{
41+
Claims.remove(Claim);
42+
}
43+
}

src/warranty/LineItem.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package warranty;
2+
3+
public class LineItem {
4+
public LineItem(double amount, String description) {
5+
super();
6+
this.amount = amount;
7+
this.description = description;
8+
}
9+
10+
public final double amount;
11+
public final String description;
12+
13+
@Override
14+
public int hashCode() {
15+
final int prime = 31;
16+
int result = 1;
17+
long temp;
18+
temp = Double.doubleToLongBits(amount);
19+
result = prime * result + (int) (temp ^ (temp >>> 32));
20+
result = prime * result
21+
+ ((description == null) ? 0 : description.hashCode());
22+
return result;
23+
}
24+
@Override
25+
public boolean equals(Object obj) {
26+
if (this == obj)
27+
return true;
28+
if (obj == null)
29+
return false;
30+
if (getClass() != obj.getClass())
31+
return false;
32+
LineItem other = (LineItem) obj;
33+
if (Double.doubleToLongBits(amount) != Double
34+
.doubleToLongBits(other.amount))
35+
return false;
36+
if (description == null) {
37+
if (other.description != null)
38+
return false;
39+
} else if (!description.equals(other.description))
40+
return false;
41+
return true;
42+
}
43+
44+
}

src/warranty/Product.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package warranty;
2+
3+
public class Product {
4+
public Product(String name, String serialNumber, String make, String model) {
5+
super();
6+
this.name = name;
7+
this.serialNumber = serialNumber;
8+
this.make = make;
9+
this.model = model;
10+
}
11+
public final String name;
12+
public final String serialNumber;
13+
public final String make;
14+
public final String model;
15+
16+
@Override
17+
public int hashCode() {
18+
final int prime = 31;
19+
int result = 1;
20+
result = prime * result + ((make == null) ? 0 : make.hashCode());
21+
result = prime * result + ((model == null) ? 0 : model.hashCode());
22+
result = prime * result + ((name == null) ? 0 : name.hashCode());
23+
result = prime * result
24+
+ ((serialNumber == null) ? 0 : serialNumber.hashCode());
25+
return result;
26+
}
27+
@Override
28+
public boolean equals(Object obj) {
29+
if (this == obj)
30+
return true;
31+
if (obj == null)
32+
return false;
33+
if (getClass() != obj.getClass())
34+
return false;
35+
Product other = (Product) obj;
36+
if (make == null) {
37+
if (other.make != null)
38+
return false;
39+
} else if (!make.equals(other.make))
40+
return false;
41+
if (model == null) {
42+
if (other.model != null)
43+
return false;
44+
} else if (!model.equals(other.model))
45+
return false;
46+
if (name == null) {
47+
if (other.name != null)
48+
return false;
49+
} else if (!name.equals(other.name))
50+
return false;
51+
if (serialNumber == null) {
52+
if (other.serialNumber != null)
53+
return false;
54+
} else if (!serialNumber.equals(other.serialNumber))
55+
return false;
56+
return true;
57+
}
58+
}

src/warranty/RepairPO.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package warranty;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class RepairPO {
7+
public List<LineItem> lineItems = new ArrayList<LineItem>();
8+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package warranty;
2+
3+
import java.text.ParseException;
4+
import java.text.SimpleDateFormat;
5+
import org.junit.Test;
6+
7+
import warranty.Contract.Status;
8+
9+
import junit.framework.Assert;
10+
11+
public class TestClaimsAdjudication {
12+
13+
@Test
14+
public void testClaimsAdjudication() throws ParseException
15+
{
16+
SimpleDateFormat sourceFormat = new SimpleDateFormat("MM-dd-yyyy");
17+
18+
Contract contract = new Contract(999, 100.0);
19+
contract.effectiveDate = sourceFormat.parse("08-05-2010");
20+
contract.expirationDate = sourceFormat.parse("08-05-2012");
21+
contract.status = Status.ACTIVE;
22+
23+
Claim claim = new Claim(888, 79.0, sourceFormat.parse("08-05-2010"));
24+
25+
ClaimsAdjudicationService adjudicator = new ClaimsAdjudicationService();
26+
27+
adjudicator.Adjudicate(contract, claim);
28+
29+
Assert.assertEquals(1, contract.getClaims().size());
30+
}
31+
32+
33+
@Test
34+
public void testClaimsAdjudicationForInvalidClaim() throws ParseException
35+
{
36+
SimpleDateFormat sourceFormat = new SimpleDateFormat("MM-dd-yyyy");
37+
38+
Contract contract = new Contract(999, 100.0);
39+
contract.effectiveDate = sourceFormat.parse("08-05-2010");
40+
contract.expirationDate = sourceFormat.parse("08-05-2012");
41+
contract.status = Status.ACTIVE;
42+
43+
Claim claim = new Claim(888, 81.0, sourceFormat.parse("08-05-2010"));
44+
45+
ClaimsAdjudicationService adjudicator = new ClaimsAdjudicationService();
46+
47+
adjudicator.Adjudicate(contract, claim);
48+
49+
Assert.assertEquals(0, contract.getClaims().size());
50+
}
51+
52+
@Test
53+
public void testClaimsAdjudicationForPendingContract() throws ParseException
54+
{
55+
SimpleDateFormat sourceFormat = new SimpleDateFormat("MM-dd-yyyy");
56+
57+
Claim claim = new Claim(888, 81.0, sourceFormat.parse("08-05-2010"));
58+
59+
Contract pendingContract = new Contract(999, 100.0);
60+
pendingContract.effectiveDate = sourceFormat.parse("08-05-2010");
61+
pendingContract.expirationDate = sourceFormat.parse("08-05-2012");
62+
pendingContract.status = Status.PENDING;
63+
64+
ClaimsAdjudicationService adjudicator = new ClaimsAdjudicationService();
65+
66+
adjudicator.Adjudicate(pendingContract, claim);
67+
68+
Assert.assertEquals(0, pendingContract.getClaims().size());
69+
}
70+
71+
@Test
72+
public void testClaimsAdjudicationForExpiredContract() throws ParseException
73+
{
74+
SimpleDateFormat sourceFormat = new SimpleDateFormat("MM-dd-yyyy");
75+
76+
Claim claim = new Claim(888, 79.0, sourceFormat.parse("08-05-2010"));
77+
78+
Contract pendingContract = new Contract(999, 100.0);
79+
pendingContract.effectiveDate = sourceFormat.parse("08-05-2010");
80+
pendingContract.expirationDate = sourceFormat.parse("08-05-2012");
81+
pendingContract.status = Status.EXPIRED;
82+
83+
ClaimsAdjudicationService adjudicator = new ClaimsAdjudicationService();
84+
85+
adjudicator.Adjudicate(pendingContract, claim);
86+
87+
Assert.assertEquals(0, pendingContract.getClaims().size());
88+
}
89+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package warranty;
2+
3+
import org.junit.Test;
4+
5+
import warranty.Contract;
6+
7+
import junit.framework.Assert;
8+
9+
public class TestContractAdmin {
10+
11+
@Test
12+
public void TestContractIsSetupCorrectly()
13+
{
14+
Contract contract = new Contract(0, 100.0);
15+
Assert.assertEquals(100.0, contract.purchasePrice);
16+
Assert.assertEquals(Contract.Status.PENDING, contract.status);
17+
}
18+
19+
}

0 commit comments

Comments
 (0)