Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Detective
- {
- private Person suspect;
- private Location suspectLocation;
- private Time suspectTime;
- private int count;
- private Oracle theOracle;
- /** Constructor
- * @param ora The reference to the Oracle
- */
- public Detective (Oracle ora)
- {
- // Initialize the data members
- //suspect = null;
- theOracle = ora;
- }
- public boolean check (String line)
- {
- boolean personcheck = false;
- // Separte the information into three categories
- String[] categories = line.split("; ");
- String[] info;
- // Get the suspect's information
- info = categories[0].split(", ");
- suspect = new Person(info[0].charAt(0), Integer.parseInt(info[1]), Double.parseDouble(info[2]));
- Person person = new Person();
- //System.out.println(theOracle.checkPerson(suspect));
- if (theOracle.checkPerson(suspect) == 0){
- return true;
- }else{
- return false;
- }
- }
- public String toString()
- {
- String str = "";
- Person person = new Person();
- System.out.println("Person: " + suspect);
- return str;
- }
- }
- import java.io.*;
- public class Driver
- {
- // The main method made this class the driver class
- public static void main (String[] args) throws IOException
- {
- // Getting the file name from the command line
- if (args.length != 2)
- {
- System.out.println("Usage: java Driver <suspect input> <oracle input>");
- System.exit(0);
- }
- String suspectInput = args[0];
- String oracleInput = args[1];
- // Create the oracle and pass it the input file
- FileReader file = new FileReader(oracleInput);
- BufferedReader buffer = new BufferedReader(file);
- String line = buffer.readLine();
- Oracle theOracle = new Oracle(line);
- // Create a dectective
- Detective detective = new Detective(theOracle);
- // Read each line of the file
- file = new FileReader(suspectInput);
- buffer = new BufferedReader(file);
- line = null;
- line = buffer.readLine();
- int count = 0;
- boolean finished = false;
- while (line != null && !finished)
- {
- if (detective.check(line))
- finished = true;
- count ++;
- line = buffer.readLine();
- }
- System.out.println("Number to times the Oracle is queried: " + theOracle.getCount());
- System.out.println("Number of suspects checked: " + count);
- System.out.println("Detective found: n" + detective);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement