Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. public class Detective
  2. {
  3. private Person suspect;
  4. private Location suspectLocation;
  5. private Time suspectTime;
  6. private int count;
  7. private Oracle theOracle;
  8.  
  9. /** Constructor
  10. * @param ora The reference to the Oracle
  11. */
  12. public Detective (Oracle ora)
  13. {
  14. // Initialize the data members
  15. //suspect = null;
  16. theOracle = ora;
  17.  
  18. }
  19.  
  20. public boolean check (String line)
  21. {
  22. boolean personcheck = false;
  23. // Separte the information into three categories
  24. String[] categories = line.split("; ");
  25. String[] info;
  26.  
  27. // Get the suspect's information
  28. info = categories[0].split(", ");
  29. suspect = new Person(info[0].charAt(0), Integer.parseInt(info[1]), Double.parseDouble(info[2]));
  30.  
  31. Person person = new Person();
  32. //System.out.println(theOracle.checkPerson(suspect));
  33. if (theOracle.checkPerson(suspect) == 0){
  34. return true;
  35. }else{
  36. return false;
  37. }
  38.  
  39. }
  40.  
  41.  
  42.  
  43.  
  44. public String toString()
  45. {
  46. String str = "";
  47. Person person = new Person();
  48. System.out.println("Person: " + suspect);
  49. return str;
  50. }
  51. }
  52.  
  53. import java.io.*;
  54.  
  55. public class Driver
  56. {
  57. // The main method made this class the driver class
  58. public static void main (String[] args) throws IOException
  59. {
  60. // Getting the file name from the command line
  61. if (args.length != 2)
  62. {
  63. System.out.println("Usage: java Driver <suspect input> <oracle input>");
  64. System.exit(0);
  65. }
  66. String suspectInput = args[0];
  67. String oracleInput = args[1];
  68.  
  69. // Create the oracle and pass it the input file
  70. FileReader file = new FileReader(oracleInput);
  71. BufferedReader buffer = new BufferedReader(file);
  72. String line = buffer.readLine();
  73. Oracle theOracle = new Oracle(line);
  74.  
  75. // Create a dectective
  76. Detective detective = new Detective(theOracle);
  77.  
  78. // Read each line of the file
  79. file = new FileReader(suspectInput);
  80. buffer = new BufferedReader(file);
  81. line = null;
  82. line = buffer.readLine();
  83. int count = 0;
  84. boolean finished = false;
  85. while (line != null && !finished)
  86. {
  87. if (detective.check(line))
  88. finished = true;
  89.  
  90. count ++;
  91. line = buffer.readLine();
  92. }
  93.  
  94. System.out.println("Number to times the Oracle is queried: " + theOracle.getCount());
  95. System.out.println("Number of suspects checked: " + count);
  96. System.out.println("Detective found: n" + detective);
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement