forked from ramram43210/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
57 lines (45 loc) · 1.54 KB
/
Copy pathClient.java
File metadata and controls
57 lines (45 loc) · 1.54 KB
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
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;
public class Client
{
public static void main( String[] args )
{
System.out.println("Please select the Expression : 'MM-DD-YYYY' or 'YYYY-MM-DD'");
Scanner scanner = new Scanner(System.in);
String expression = scanner.next();
Context context = new Context();
context.setExpression(expression);
context.setDate(new Date());
ArrayList<AbstractExpression> expressionOrderList = getExpressionOrder(context);
System.out.println("Input : " + context.getExpression() + " : " + new Date());
for( AbstractExpression abstractExpression : expressionOrderList )
{
abstractExpression.evaluate(context);
System.out.println(abstractExpression.getClass().getName() + " Evaluated : "
+ context.getExpression());
}
System.out.println("Output : " + context.getExpression());
}
private static ArrayList<AbstractExpression> getExpressionOrder( Context context )
{
ArrayList<AbstractExpression> expressionOrderList = new ArrayList<AbstractExpression>();
String[] strArray = context.getExpression().split("-");
for( String string : strArray )
{
if( string.equalsIgnoreCase("MM") )
{
expressionOrderList.add(new MonthExpression());
}
else if( string.equalsIgnoreCase("DD") )
{
expressionOrderList.add(new DayExpression());
}
else
{
expressionOrderList.add(new YearExpression());
}
}
return expressionOrderList;
}
}