package prison;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Prison {
private List<Prisoner> prisoners = new ArrayList<>();
public Prison() {
}
public List<Prisoner> getPrisoners() {
return prisoners;
}
public void addPrisoner(Prisoner prisoner) {
prisoners.add(prisoner);
}
public void removePrisoner(Scanner scanner) {
System.out.println("Enter the name of the prisoner you want to remove: ");
String name = scanner.nextLine();
for (Prisoner p : prisoners) {
if (p.getName().equalsIgnoreCase(name)) {
prisoners.remove(p);
return;
}
}
}
public void loadFile(Scanner scanner) {
System.out.println("Enter path:");
String path = scanner.nextLine();
try {
String jsonString = new String(Files.readAllBytes(Paths.get(path)));
JSONArray jsonArray = new JSONArray(jsonString);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
Prisoner prisoner = new Prisoner(jsonObject);
prisoners.add(prisoner);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void printPrisoners() {
for (Prisoner p : prisoners) {
System.out.println(p.toString());
}
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}