-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChainOfResposibility.java
81 lines (76 loc) · 2.31 KB
/
ChainOfResposibility.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
abstract class DetectionHandler
{
DetectionHandler next;
public void setNext(DetectionHandler next) {
this.next = next;
}
public abstract void Validate(double amount, String location, String merchant, String algo,double withdrawal);
}
class BasicCheck extends DetectionHandler
{
@Override
public void Validate(double amount, String location, String merchant, String algo, double withdrawal) {
if(amount<=100000||withdrawal<=100000)
{
System.out.println("transcation completed by BasicCheck");
}
else
{
next.Validate(amount, location, merchant, algo, withdrawal);
}
}
}
class Geographical extends DetectionHandler
{
@Override
public void Validate(double amount, String location, String merchant, String algo, double withdrawal) {
if(location.equals("Bangladesh"))
{
System.out.println("transcation completed by Geographical");
}
else
{
next.Validate(amount, location, merchant, algo, withdrawal);
}
}
}
class Merchant extends DetectionHandler
{
@Override
public void Validate(double amount, String location, String merchant, String algo, double withdrawal) {
if(merchant.equals("Black-listed"))
{
next.Validate(amount, location, merchant, algo, withdrawal);
}
else
{
System.out.println("transcation completed by Merchant");
}
}
}
class Algo extends DetectionHandler
{
@Override
public void Validate(double amount, String location, String merchant, String algo, double withdrawal) {
if(algo.equals("verified"))
{
System.out.println("transcation completed by Algo");
}
else
{
System.out.println("transcation rejected");
}
}
}
public class ChainOfResposibility {
public static void main(String[] args) {
DetectionHandler handler = new BasicCheck();
DetectionHandler merchant = new Merchant();
DetectionHandler algo = new Algo();
DetectionHandler transcation = new Geographical();
handler.setNext(transcation);
transcation.setNext(merchant);
merchant.setNext(algo);
handler.Validate(200000,"Bangladesh","Normal","machine",200000);
}
}