package mainservlets;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import mainservlets.ResultJson;
import com.google.gson.Gson;
public class WriteOutJsonNextRound{
private double [] Lottery0;
private double [] Lottery1;
private int id;
private String dir;
//private String dir = "C:/workspace/TimePrefServletWithLockFile/TMP/";
//private String dir = "C:/workspace/BROAD/TMP/";
public WriteOutJsonNextRound(int id,double [] Lottery0, double[] Lottery1, String dir){
this.Lottery0 = Lottery0;
this.Lottery1 = Lottery1;
this.id = id;
this.dir = dir + "TMP/";
}
public void write(){
ResultJson[] rjs = new ResultJson[] {new ResultJson(Lottery0), new ResultJson(Lottery1)};
Gson gson = new Gson();
String json_lott = gson.toJson(rjs);
File file = new File(this.dir + "nextround_"+id+".json");
PrintWriter printWriter;
try {
printWriter = new PrintWriter(new BufferedWriter(new FileWriter(file, false)));
printWriter.println(json_lott);
printWriter.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/*
* This is for building a json object.
*/
class ResultJson {
private double days;
private double money;
public ResultJson(double [] Lottery){
this.money = Lottery[0];
this.days = Lottery[1];
}
}