Commit dd115048 authored by Kevin's avatar Kevin
Browse files

nambah fitur mixedItem

parent 6e4ec89c
{"kevin":{"r21":0,"r32":0,"r31":0,"password":"123","r12":0,"r23":0,"r11":0,"r22":0,"r14":0,"r13":0,"position":"nanti_dipikirin","r41":0}}
\ No newline at end of file
{"kevin":{"r21":0,"r32":0,"r31":0,"password":"123","r12":5,"r23":0,"r11":6,"r22":0,"r14":0,"r13":0,"position":"nanti_dipikirin","r41":0}}
......@@ -44,13 +44,156 @@ public class EndpointMethod {
}
} catch (Exception e) {
e.printStackTrace();
}
}
resultJson.put("status", "error");
return resultJson.toString();
}
public static void main(String argv[]) throws IOException, ParseException{
EndpointMethod tes=new EndpointMethod();
public String mixItem(String username, String item1, String item2) {
JSONObject resultJson = new JSONObject();
JSONParser parser = new JSONParser();
try {
String basePath = new File("").getAbsolutePath();
Object obj = parser.parse(new FileReader(basePath + "//file_saved.json"));
if (obj != null) {
JSONObject jsonFile = (JSONObject) obj;
JSONObject userJson = (JSONObject) jsonFile.get(username.toLowerCase());
if (item1.equalsIgnoreCase("r11") && item2.equalsIgnoreCase("r12")) {
long nItem1;
long nItem2;
nItem1 = ((Long) userJson.get(item1)).longValue();
nItem2 = ((Long) userJson.get(item2)).longValue();
if ((nItem1 > 2) && (nItem2 > 2)) {
nItem1 -= 3;
nItem2 -= 3;
// Ganti data di database
// userJson.put(item1,nItem1);
// userJson.put(item2,nItem2);
// userJson.put("r21", );
resultJson.put("status", "ok");
resultJson.put("item", "r21");
return resultJson.toString();
} else {
resultJson.put("status", "fail");
resultJson.put("description", "Your item count doesn't satisfy to make the new item");
return resultJson.toString();
}
} else if (item1.equalsIgnoreCase("r12") && item2.equalsIgnoreCase("r13")) {
long nItem1;
long nItem2;
nItem1 = ((Long) userJson.get(item1)).longValue();
nItem2 = ((Long) userJson.get(item2)).longValue();
if ((nItem1 > 2) && (nItem2 > 2)) {
nItem1 -= 3;
nItem2 -= 3;
// Ganti data di database
// userJson.put(item1,nItem1);
// userJson.put(item2,nItem2);
// userJson.put("r21", );
resultJson.put("status", "ok");
resultJson.put("item", "r22");
return resultJson.toString();
} else {
resultJson.put("status", "fail");
resultJson.put("description", "Your item count doesn't satisfy to make the new item");
return resultJson.toString();
}
} else if (item1.equalsIgnoreCase("r13") && item2.equalsIgnoreCase("r14")) {
long nItem1;
long nItem2;
nItem1 = ((Long) userJson.get(item1)).longValue();
nItem2 = ((Long) userJson.get(item2)).longValue();
if ((nItem1 > 2) && (nItem2 > 2)) {
nItem1 -= 3;
nItem2 -= 3;
// Ganti data di database
// userJson.put(item1,nItem1);
// userJson.put(item2,nItem2);
// userJson.put("r21", );
resultJson.put("status", "ok");
resultJson.put("item", "r23");
return resultJson.toString();
} else {
resultJson.put("status", "fail");
resultJson.put("description", "Your item count doesn't satisfy to make the new item");
return resultJson.toString();
}
} else if (item1.equalsIgnoreCase("r21") && item2.equalsIgnoreCase("r22")) {
long nItem1;
long nItem2;
nItem1 = ((Long) userJson.get(item1)).longValue();
nItem2 = ((Long) userJson.get(item2)).longValue();
if ((nItem1 > 2) && (nItem2 > 2)) {
nItem1 -= 3;
nItem2 -= 3;
// Ganti data di database
// userJson.put(item1,nItem1);
// userJson.put(item2,nItem2);
// userJson.put("r21", );
resultJson.put("status", "ok");
resultJson.put("item", "r31");
return resultJson.toString();
} else {
resultJson.put("status", "fail");
resultJson.put("description", "Your item count doesn't satisfy to make the new item");
return resultJson.toString();
}
} else if (item1.equalsIgnoreCase("r22") && item2.equalsIgnoreCase("r23")) {
long nItem1;
long nItem2;
nItem1 = ((Long) userJson.get(item1)).longValue();
nItem2 = ((Long) userJson.get(item2)).longValue();
if ((nItem1 > 2) && (nItem2 > 2)) {
nItem1 -= 3;
nItem2 -= 3;
// Ganti data di database
// userJson.put(item1,nItem1);
// userJson.put(item2,nItem2);
// userJson.put("r21", );
resultJson.put("status", "ok");
resultJson.put("item", "r32");
return resultJson.toString();
} else {
resultJson.put("status", "fail");
resultJson.put("description", "Your item count doesn't satisfy to make the new item");
return resultJson.toString();
}
} else if (item1.equalsIgnoreCase("r31") && item2.equalsIgnoreCase("r32")) {
long nItem1;
long nItem2;
nItem1 = ((Long) userJson.get(item1)).longValue();
nItem2 = ((Long) userJson.get(item2)).longValue();
if ((nItem1 > 2) && (nItem2 > 2)) {
nItem1 -= 3;
nItem2 -= 3;
// Ganti data di database
// userJson.put(item1,nItem1);
// userJson.put(item2,nItem2);
// userJson.put("r21", );
resultJson.put("status", "ok");
resultJson.put("item", "r41");
return resultJson.toString();
} else {
resultJson.put("status", "fail");
resultJson.put("description", "Your item count doesn't satisfy to make the new item");
return resultJson.toString();
}
} else {
resultJson.put("status", "fail");
resultJson.put("description", "Your mixed items doesn't match the recipe diagram");
return resultJson.toString();
}
}
} catch (Exception e) {
e.printStackTrace();
}
resultJson.put("status", "error");
return resultJson.toString();
}
public static void main(String argv[]) throws IOException, ParseException {
// EndpointMethod tes = new EndpointMethod();
// System.out.println(tes.inventory("Kevi"));
// System.out.println(tes.mixItem("Kevin", "r11", "r23"));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment