Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public NuxCarRental(Scanner file){
- if(file == null){
- return;
- }
- customers = new Queue<Customer>();
- detailShop = new Queue<Car>();
- repairShop = new Queue<Car>();
- availableCars = new Stack<Car>();
- rentedCars = new Queue<Car>();
- String line;
- String make;
- String model;
- String color;
- String fleetNum;
- String status;
- String firstName;
- String lastName;
- String customerID;
- int wordCount = 0;
- String lineContext;
- while(file.hasNextLine()) {
- line = file.nextLine();
- lineContext = line;
- while(lineContext.indexOf(",") != -1){
- wordCount++;
- lineContext = line.substring(line.indexOf(",") + 1);
- }
- wordCount++;
- //only Car parameters exists
- if(wordCount == 5){
- make = line.substring(0, line.indexOf(","));
- line = line.substring(line.indexOf(",") + 1);
- model = line.substring(0, line.indexOf(","));
- line = line.substring(line.indexOf(",") + 1);
- color = line.substring(0, line.indexOf(","));
- line = line.substring(line.indexOf(",") + 1);
- fleetNum = line.substring(0, line.indexOf(","));
- line = line.substring(line.indexOf(",") + 1);
- status = line;
- if(!status.equals("R")){
- processNewCar(make, model, color, fleetNum);
- }
- }
- boolean flag = true;
- //Both Car and Customer parameters are present
- if(wordCount == 7){
- make = line.substring(0, line.indexOf(","));
- line = line.substring(line.indexOf(",") + 1);
- model = line.substring(0, line.indexOf(","));
- line = line.substring(line.indexOf(",") + 1);
- color = line.substring(0, line.indexOf(","));
- line = line.substring(line.indexOf(",") + 1);
- fleetNum = line.substring(0, line.indexOf(","));
- line = line.substring(line.indexOf(",") + 1);
- status = line.substring(0, line.indexOf(","));
- line = line.substring(line.indexOf(",") + 1);
- lastName = line.substring(0, line.indexOf(","));
- line = line.substring(line.indexOf(",") + 1);
- customerID = line;
- firstName = lastName.substring(0, lastName.indexOf(" "));
- lastName = lastName.substring(lastName.indexOf(" ") + 1);
- try{
- Customer newCustomer = new Customer(firstName, lastName, customerID);
- Car newCar = new Car(make, model, color, fleetNum);
- Rented rentedState = new Rented(newCustomer);
- newCar.setState(rentedState);
- addCar(newCar);
- } catch (InvalidIDException | IllegalArgumentException d){
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement