importjava.io.*;importjava.util.ArrayList;importjava.util.List;importjava.util.Objects;importjava.util.Random;/**
* COMP90041, Sem1, 2023: Final Project
* @author:
* student id:
* student email:
*/publicclassRescueBot{publicstaticList<Scenario> scenarioList =newArrayList<>();/**
* Decides whether to save the passengers or the pedestrians
* @param scenario: the ethical dilemma
*/publicstaticvoiddecide(Scenario scenario){// a very simple decision engine// TODO: take into account at least 5 characteristics
scenario.setJudged(true);for(Location location : scenario.getLocationList()){// if is trespassing don't choiceif(location.isTrespassing()){continue;}// if average age below 40 save this locationif(location.getAverageAge()<40){
location.setSaved(true);return;}// if location has pregnant saveif(location.hasPregnant()){
location.setSaved(true);return;}if(location.hasSpecialAnimal()){
location.setSaved(true);return;}if(location.hasFemale()){
location.setSaved(true);return;}}// random choiceRandom random =newRandom();int i = random.nextInt(0, scenario.getLocationList().size());
scenario.getLocationList().get(i).setSaved(true);}/**
* Program entry
*/publicstaticvoidmain(String[] args){getArgs(args);UserOutput.welcome();ReadFromFile readFromFile =newReadFromFile();if(ProgramSet.scenarioPath !=null){
readFromFile.readFromCSV(scenarioList,ProgramSet.scenarioPath);System.out.println(scenarioList.size()+" scenarios imported.");}String option;while(true){try{UserOutput.showCommands();
option =UserInput.scanner.next();if(Objects.equals(option,"judge")||Objects.equals(option,"j")){MainMenu.judge(scenarioList);System.out.print(" ");}elseif(Objects.equals(option,"run")||Objects.equals(option,"r")){MainMenu.runSimulation(scenarioList);System.out.print(" ");}elseif(Objects.equals(option,"audit")||Objects.equals(option,"a")){MainMenu.audit(scenarioList);System.out.print(" ");}elseif(Objects.equals(option,"quit")||Objects.equals(option,"q")){System.exit(0);}else{UserOutput.showInvalidCommands();}}catch(Exception ignore){}}}privatestaticvoidgetArgs(String[] args){if(args.length ==0){return;}if(Objects.equals(args[0],"-h")||Objects.equals(args[0],"--help")){UserOutput.help();}for(int i =0; i < args.length -1; i++){if(Objects.equals(args[i],"-s")||Objects.equals(args[i],"--scenarios")){String path = args[i +1];try(InputStream inputStream =newFileInputStream(path)){ProgramSet.scenarioPath = path;}catch(FileNotFoundException e){System.out.println("java.io.FileNotFoundException: could not find scenarios file.");UserOutput.help();}catch(IOException ignore){}}elseif(Objects.equals(args[i],"-l")||Objects.equals(args[i],"--log")){ProgramSet.logPath = args[i +1];}}}}