-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestCases.java
More file actions
111 lines (96 loc) · 4.35 KB
/
TestCases.java
File metadata and controls
111 lines (96 loc) · 4.35 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Calendar;
public class TestCases {
public static void main(String[] args) throws FileNotFoundException {
SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd");
Date StartDate = new Date(),EndDate = new Date();
try {
StartDate = ft.parse("2004-02-09");
} catch (ParseException ex) {
Logger.getLogger(TestCases.class.getName()).log(Level.SEVERE, null, ex);
}
try {
EndDate = ft.parse("2017-06-15");
} catch (ParseException ex) {
Logger.getLogger(TestCases.class.getName()).log(Level.SEVERE, null, ex);
}
String fileWrite = "";//Format of string is
//ID,StartDate,EndDate,No of Days,Rate,Principal,Paid,Percentage paid
Calendar start = Calendar.getInstance();
start.setTime(StartDate);
Calendar end = Calendar.getInstance();
end.setTime(EndDate);
int i = 1;
for (Date date = start.getTime(); start.before(end); start.add(Calendar.DATE, 1), date = start.getTime()) {
// Do your job here with `date`.
fileWrite += Integer.toString(i++);
fileWrite += ",";
fileWrite += ft.format(date);
fileWrite += ",";
int principal = ThreadLocalRandom.current().nextInt(10000, 101010101 + 1);
fileWrite += Integer.toString(principal);
fileWrite += ",";
Random rand = new Random();
float percentage = (float) (rand.nextFloat() * (100.0));
percentage = (float) ((float) Math.round(percentage * 100.0d)/100.0d);
double paid = (double) (principal * percentage/100.0);
paid = (double) ((double) Math.round(paid * 100.0d)/100.0d);
DecimalFormat df = new DecimalFormat("#");
df.setMaximumFractionDigits(5);
fileWrite += df.format(paid);
fileWrite += ",";
fileWrite += Float.toString(percentage);
fileWrite += "\n";
}
System.out.println(fileWrite);
try (PrintStream out = new PrintStream(new FileOutputStream("TestCsvData.csv"))) {
out.print(fileWrite);
}
/*
for(int i=1;i<=1000;i++){
fileWrite += Integer.toString(i);
fileWrite += ",";
long random = ThreadLocalRandom.current().nextLong(StartDate.getTime(), EndDate.getTime());
Date start = new Date(random);
fileWrite += ft.format(start);
fileWrite += ",";
random = ThreadLocalRandom.current().nextLong(start.getTime(), EndDate.getTime());
Date end = new Date(random);
fileWrite += ft.format(end);
fileWrite += ",";
int diffInDays;
diffInDays = (int)( (end.getTime() - start.getTime())/ (1000 * 60 * 60 * 24) );
fileWrite += Integer.toString(diffInDays);
fileWrite += ",13,";
int principal = ThreadLocalRandom.current().nextInt(10000, 101010101 + 1);
fileWrite += Integer.toString(principal);
fileWrite += ",";
Random rand = new Random();
float percentage = (float) (rand.nextFloat() * (100.0));
percentage = (float) ((float) Math.round(percentage * 100.0d)/100.0d);
double paid = (double) (principal * percentage/100.0);
paid = (double) ((double) Math.round(paid * 100.0d)/100.0d);
DecimalFormat df = new DecimalFormat("#");
df.setMaximumFractionDigits(5);
fileWrite += df.format(paid);
fileWrite += ",";
fileWrite += Float.toString(percentage);
fileWrite += "\n";
}
//System.out.println(fileWrite);
try (PrintStream out = new PrintStream(new FileOutputStream("TestCsvData.csv"))) {
out.print(fileWrite);
}
*/
}
}