public void reserve(Passenger passenger) {
   passCollection.add(passenger);
   System.out.println(
       passenger.getFirstName()
           + " "
           + passenger.getLastName()
           + " has BOOKED their reservation for the flight.");
 }
示例#2
0
文件: Engine.java 项目: jcooky/fecs
  public void updateCabin(Cabin cabin, double deltaTime) {
    if (deltaTime > 0.2) return;
    if (cabin.isOn()) {
      switch (cabin.getState()) {
        case MOVE:
          double vector = cabin.getVector();
          int vectorUnit = (int) (vector / Math.abs(vector));
          double motor = motorOutput * earthGravity * deltaTime; // Nm/s (weight) -> kgfm
          if (motor <= gravity) {
            logger.debug("motor is too weak or gravity is too strong.");
            motor = gravity;
          }
          Floor target = cabin.getTarget();
          double leftVector = target.getPosition() - cabin.getPosition();
          int leftVectorUnit = (int) (leftVector / Math.abs(leftVector));
          double accel = motor / mass(cabin) * leftVectorUnit;
          if (Math.abs(cabin.getVelocity()) > 1)
            accel *= Math.abs(vector * 0.5) < Math.abs(leftVector) ? 1 : -1; // brake on half point
          if (Double.isNaN(accel)) {
            accel = vectorUnit;
          }
          //          logger.debug(String.format("%f -> %f (%f) : %f",cabin.getPosition(),
          // target.getPosition(),vector,accel));
          //          logger.debug(String.format("%s->%d, %f, %f,
          // %f",cabin.getName(),target.getNum(),accel,leftVector,vector*0.5));
          updateCabin(cabin, accel, deltaTime);

          if (Math.abs(leftVector) < CABIN_MOVE_THRESHOLD) { // arrive
            cabin.setPosition(target.getPosition());
            cabin.stop();
            //            cabin.getQueue().remove(target);
            logger.debug(String.format("%s->%d done", cabin.getName(), target.getNum()));
          }
          break;
        case STOP:
          logger.info("cabin({}) arrived", cabin.getName());

          for (Floor floor : floors.values()) {
            if (cabin.getPosition() == floor.getPosition()) {
              logger.debug("on {}", floor);
              Iterator<Passenger> it = cabin.getPassengers().iterator();
              while (it.hasNext()) {
                Passenger p = it.next();
                if (p.getDest().equals(floor.getNum())) {
                  p.setState(Passenger.State.NO_WAIT);
                  it.remove();
                  floor.getPassengers().add(p);
                }
              }
              cabin.getQueue().remove(floor);
            }
          }

          if (cabin.getQueue().size() > 0) cabin.move(); // to next queued floor
          break;
      }
    }
  }
示例#3
0
  /**
   * Create a booking for a regular passenger with no seat specified.
   *
   * @param p the passenger for whom a booking is to be made
   * @precond p != null && !p.hasBookingOn(this) && remainingCapacity() > 0
   */
  public void makeBooking(Passenger p) {
    if (p == null) throw new RuntimeException("Cannot book a flight for a null passenger.");
    if (p.hasBookingOn(this)) throw new RuntimeException("Cannot book a Person twice on a Flight.");
    if (remainingCapacity() <= 0)
      throw new RuntimeException("Cannot make a booking on a full flight.");

    Booking b = new Booking(p, this);
    waitingSeatList.addLast(b);
    p.addBooking(b);
    numberBooked = numberBooked + 1;
  }
示例#4
0
 @Test
 public void testYoungBus_TownBus_Metro() throws Exception {
   // Given
   Passenger young = new YoungAdult();
   // When
   young.addVehicle(new Bus_Town(young));
   young.addVehicle(new Bus_Metro(young));
   double fee = young.calcFee();
   // Then
   assertEquals(1700, fee, 0);
 }
示例#5
0
  /**
   * Book a seat for a first-class passenger.
   *
   * @param p the passenger for whom a booking is to be made
   * @param seat the seat for the passenger
   * @param meal the meal plan for the passenger
   * @precond p != null && !p.hasBookingOn(this) && isSeatAvailable(seat)
   */
  public void makeFirstClassBooking(Passenger p, String seat, String meal) {
    if (p == null) throw new RuntimeException("Cannot book a flight for a null passenger.");
    if (p.hasBookingOn(this)) throw new RuntimeException("Cannot book a Person twice on a Flight.");
    if (!isSeatAvailable(seat))
      throw new RuntimeException(
          "Seat " + seat + " is invalid or already occupied " + "so cannot book it.");

    Booking b = new FirstClassBooking(p, this, seat, meal);
    setSeat(b);
    p.addBooking(b);
    numberBooked = numberBooked + 1;
  }
示例#6
0
  @Test
  public void testAdultBusBus_Metro() throws Exception {
    // Given
    Passenger adult = new Adult();

    // When
    adult.addVehicle(new Bus(new Point(0, 0), new Point(0, 20)));
    adult.addVehicle(new Bus_Metro(adult));
    double fee = adult.calcFee();
    // Then

    assertEquals(1900, fee, 0);
  }
示例#7
0
  public String displaySeatDetails() {
    String output = "";
    String seatStatus = "";

    switch (currentStatus) {
      case 1:
        seatStatus = "Free";
        break;
      case 2:
        seatStatus = "Reserved";
        break;
      case 3:
        seatStatus = "Booked";
        break;
    }
    output =
        "<html> Seat No: "
            + seatNo
            + "<br /> Current Status: "
            + seatStatus
            + "<br /> Seat Price: £"
            + seatTakings;

    if (seatStatus.equals("booked")) {
      output += "<br /> Passenger Name: " + passenger.getPassengerName();
    }

    output += output + "</html>";
    return output;
  }
 public void displayFlightInfo() {
   System.out.println(
       "Flight "
           + getFlightNumber()
           + " in the "
           + aircraft.getAircraftType()
           + " is ready for boarding.");
   System.out.println("Here is the final boarding list for this flight:\n");
   for (Passenger p : passCollection) {
     if (p.getStatus()) setAmount(112.50);
     else setAmount(75.00);
     System.out.println(
         p.getFirstName()
             + " "
             + p.getLastName()
             + " - "
             + (p.getStatus() ? "FIRST CLASS" : "ECONOMY CLASS")
             + " passenger. $"
             + getAmount()); // (p.getStatus()? 112.50 : 75.00));
   }
 }
  /**
   * Load game state from file
   *
   * @param path Path to file
   */
  public void deserialize(String path) {
    try {
      for (int i = 0; i < getVehicles().size(); i++) {
        getVehicles().get(i).stopThread();
      }

      for (int i = 0; i < getIntersections().size(); i++) {
        getIntersections().get(i).stopThread();
      }

      Passenger p = passengers.poll();
      while (p != null) {
        p.stopThread();
        p = passengers.poll();
      }

      vehicles = null;
      intersections = null;
      passengers = null;
      //            DrawPanel.getInstance() = null;
      //            VehicleInspector.getInstance() = null;
      _instance = null;

      // Just to make sure things are right
      Thread.sleep(500);

      ObjectInputStream in =
          new ObjectInputStream(new BufferedInputStream(new FileInputStream(path)));

      _instance = (WorldManager) in.readObject();
      in.close();
      Thread.sleep(500);

      announceWorldChange();
      System.out.println("Deserialized!");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#10
0
  /**
   * Assign passenger p who has a booking but no seat to the specified seat.
   *
   * @param p the passenger to be given a seat
   * @param seat the seat for the passenger
   * @precond p != null && isSeatAvailable(seat) && p.hasBookingOn(this) && !p.hasSeatOn(this)
   */
  public void assignSeat(Passenger p, String seat) {
    if (p == null) throw new RuntimeException("Cannot assign a seat for a null passenger.");
    if (!isSeatAvailable(seat))
      throw new RuntimeException(
          "Seat " + seat + " is invalid or already occupied " + "so cannot book it.");
    if (p.hasSeatOn(this))
      throw new RuntimeException(
          p.getName()
              + " already has a seat on flight "
              + getNumber()
              + " so cannot book another one.");

    Iterator<Booking> waitingIter = waitingSeatList.iterator();
    while (waitingIter.hasNext()) {
      Booking curBooking = waitingIter.next();
      if (curBooking.getPerson() == p) {
        waitingIter.remove();
        curBooking.setSeat(seat);
        setSeat(curBooking);
        return;
      }
    }
    throw new RuntimeException("Cannot assign a seat if not already booked and waiting.");
  }
示例#11
0
 public void cancel(Passenger passenger) {
   for (Passenger p : passCollection) {
     if (p.getFirstName() == passenger.getFirstName()) {
       if (p.getLastName() == passenger.getLastName()) {
         passCollection.remove(p);
         System.out.println(
             p.getFirstName()
                 + " "
                 + p.getLastName()
                 + " has CANCELLED their reservation for the flight.\n");
         break;
       }
     }
   }
 }
示例#12
0
  public void simulate(ArrayList<Passenger> exitedPassengers, int time) {
    if (hasArrivedTrain(time)) {
      int officeArrivingTime;
      int ticketingWaitingTime;
      int ticketingTime;
      int platformArrivingTime;
      for (int i = 0; i < waitingPassengers.size(); i++) {
        Passenger passenger = waitingPassengers.get(i);
        officeArrivingTime = passenger.getOfficeArrivalTime();
        ticketingWaitingTime = passenger.getTicketingWaitingTime();
        ticketingTime = passenger.getTicketingTime();
        platformArrivingTime = officeArrivingTime + ticketingWaitingTime + ticketingTime;
        passenger.setTrainWaitingTime(time - platformArrivingTime);
        int travelTime = path.getTravelTime(passenger.getStartPoint(), passenger.getEndPoint());
        passenger.setDestinationArrivalTime(time + travelTime);
      }

      dequeueAll(exitedPassengers);
    }
  }
示例#13
0
  public int changeSeatStatus(
      Airline myAirline, int newStatus, Passenger newPassenger, Flight newFlight) {
    UserInterface ui = new UserInterface(myAirline);

    if (newStatus == 1) {
      if (currentStatus == 1) {
        ui.genericOutput("Seat Number: " + seatNo + " Is Already Free");
        return -1;
      } else if (currentStatus == 2) {
        currentStatus = 1;
        passenger = null;
        completeSeatStatus = 1;
        ui.genericOutput("Seat Number: " + seatNo + " Has Been Cancelled");
      } else if (currentStatus == 3) {
        currentStatus = 1;
        passenger = null;
        completeSeatStatus = 2;
        ui.genericOutput("Seat Number: " + seatNo + " Has Been Cancelled - No Refund");
      }
    } else if (newStatus == 2) {
      if (currentStatus == 1) {
        currentStatus = 2;
        passenger = newPassenger;
        completeSeatStatus = 3;
        ui.genericOutput(
            "Seat Number: "
                + seatNo
                + " Has Now Been Reserved By "
                + newPassenger.getPassengerName());

      } else if (currentStatus == 2) {
        ui.genericOutput(
            "Seat Number: " + seatNo + " Is Already Reserved By " + passenger.getPassengerName());
        return -1;

      } else if (currentStatus == 3) {
        ui.genericOutput(
            "Seat Number: " + seatNo + " Is Already Booked By " + passenger.getPassengerName());
        return -1;
      }
    } else if (newStatus == 3) {
      if (currentStatus == 1) {
        currentStatus = 3;
        passenger = newPassenger;
        completeSeatStatus = 4;
        seatTakings += (seatPrice * newPassenger.getDiscountAmount());
        ui.genericOutput(
            "Seat Number: "
                + seatNo
                + " Has Now Been Booked By "
                + newPassenger.getPassengerName());

      } else if (currentStatus == 2) {
        if (newPassenger.getPassengerName().equalsIgnoreCase(passenger.getPassengerName())) {
          currentStatus = 3;
          passenger = newPassenger;
          completeSeatStatus = 5;
          seatTakings += (seatPrice * newPassenger.getDiscountAmount());
          ui.genericOutput(
              "Seat Number: "
                  + seatNo
                  + " Has Now Been Booked By "
                  + newPassenger.getPassengerName());
        } else {
          ui.genericOutput(
              "Seat Number: " + seatNo + " Is Already Reserved By " + passenger.getPassengerName());
          return -1;
        }
      }
    }
    return completeSeatStatus;
  }
  /**
   * This method reports that a passenger is taking stairs (no elevator is available on the
   * appropriate floor).
   *
   * @param newPass Passenger object for this passenger
   */
  private static void takingStairs(Passenger newPass) {
    System.out.print(
        "Passenger " + newPass.getName() + " arrives on floor " + newPass.getFloor() + ".");

    System.out.println(" Taking stairs.");
  } //  end takingStairs
  /**
   * Read and process each item in the simulation file. It reads each input item in the file. If a
   * PASSENGER entry, a passenger object is created, and the elevators are checked to see if one is
   * available to service this passenger. If so, the passenger is logically added to the elevator.
   * If an elevator is not available, the passenger must take the stairs.
   *
   * <p>If the input item is a TICK, it indicates that one time unit has passed. At EOF, the method
   * is invoked to shut the elevators down and perform the end of day processing.
   *
   * <p>If an error is detected at any time, this method returns the proper boolean to the calling
   * method.
   *
   * @return True or False to indicate an error
   */
  private static boolean processSimulationFile() {

    // local constants used by this method

    final String PASSENGER = "passenger";
    final String TICK = "tick";
    final String SIMULATION_END = "done";

    boolean done = false; // set when done
    boolean error = false; // set if error detected
    boolean addedOK = false; // set if no elevator is available
    Passenger newPass = null; // new passenger object
    Elevator availableEl = null; // elevator object

    // Read next token from file and process

    try {
      while (!done && !error && in.nextToken() != in.TT_EOF) {

        if (in.sval.equals(PASSENGER)) {
          //  if a new passenger, create a new object, look
          //  for an elevator and add to elevator.  If elevator
          //  is not available, passenger takes the stairs.

          newPass = newPassenger();
          availableEl = findElevator(newPass);
          if (availableEl == null) takingStairs(newPass);
          else {
            System.out.print(
                "Passenger: "
                    + newPass.getName()
                    + " arrives on floor "
                    + newPass.getFloor()
                    + ".");
            addedOK = availableEl.addPassenger(newPass);
            if (!addedOK) {
              error = true;
            }
          }
        } else if (in.sval.equals(TICK)) {
          // token read from file is a time indicator
          recordTick();

        } else if (in.sval.equals(SIMULATION_END)) {
          // end of file == end of workday
          done = true;
        } else {
          error = true;
        }
      } // end while

      if (in.nextToken() == in.TT_EOF) {
        //  perform end of day reporting
        endOfDay();
      }

      // catch for file exception
    } catch (IOException e) {
      error = true;
    } // end try

    return error;
  } //  end processSimulationFile
示例#16
0
 /**
  * Receive a passenger. Add their destination to the list.
  *
  * @param passenger The passenger being picked up.
  */
 public void pickup(Passenger passenger) {
   passengers.add(passenger);
   destinations.add(passenger.getDestination());
   chooseTargetLocation();
 }