Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. public NuxCarRental(Scanner file){
  2. if(file == null){
  3. return;
  4. }
  5. customers = new Queue<Customer>();
  6. detailShop = new Queue<Car>();
  7. repairShop = new Queue<Car>();
  8. availableCars = new Stack<Car>();
  9. rentedCars = new Queue<Car>();
  10.  
  11. String line;
  12. String make;
  13. String model;
  14. String color;
  15. String fleetNum;
  16. String status;
  17. String firstName;
  18. String lastName;
  19. String customerID;
  20. int wordCount = 0;
  21. String lineContext;
  22.  
  23. while(file.hasNextLine()) {
  24. line = file.nextLine();
  25. lineContext = line;
  26. while(lineContext.indexOf(",") != -1){
  27. wordCount++;
  28. lineContext = line.substring(line.indexOf(",") + 1);
  29. }
  30. wordCount++;
  31.  
  32. //only Car parameters exists
  33. if(wordCount == 5){
  34. make = line.substring(0, line.indexOf(","));
  35. line = line.substring(line.indexOf(",") + 1);
  36. model = line.substring(0, line.indexOf(","));
  37. line = line.substring(line.indexOf(",") + 1);
  38. color = line.substring(0, line.indexOf(","));
  39. line = line.substring(line.indexOf(",") + 1);
  40. fleetNum = line.substring(0, line.indexOf(","));
  41. line = line.substring(line.indexOf(",") + 1);
  42. status = line;
  43. if(!status.equals("R")){
  44. processNewCar(make, model, color, fleetNum);
  45. }
  46. }
  47. boolean flag = true;
  48. //Both Car and Customer parameters are present
  49. if(wordCount == 7){
  50. make = line.substring(0, line.indexOf(","));
  51. line = line.substring(line.indexOf(",") + 1);
  52. model = line.substring(0, line.indexOf(","));
  53. line = line.substring(line.indexOf(",") + 1);
  54. color = line.substring(0, line.indexOf(","));
  55. line = line.substring(line.indexOf(",") + 1);
  56. fleetNum = line.substring(0, line.indexOf(","));
  57. line = line.substring(line.indexOf(",") + 1);
  58. status = line.substring(0, line.indexOf(","));
  59. line = line.substring(line.indexOf(",") + 1);
  60. lastName = line.substring(0, line.indexOf(","));
  61. line = line.substring(line.indexOf(",") + 1);
  62. customerID = line;
  63. firstName = lastName.substring(0, lastName.indexOf(" "));
  64. lastName = lastName.substring(lastName.indexOf(" ") + 1);
  65. try{
  66. Customer newCustomer = new Customer(firstName, lastName, customerID);
  67. Car newCar = new Car(make, model, color, fleetNum);
  68. Rented rentedState = new Rented(newCustomer);
  69. newCar.setState(rentedState);
  70. addCar(newCar);
  71. } catch (InvalidIDException | IllegalArgumentException d){
  72. }
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement