Ejemplo n.º 1
0
 /**
  * Prints the motos of a list.
  *
  * @param aux list to be printed out.
  */
 private void printMotoList(ArrayList<Moto> aux) {
   int i = 0;
   for (Moto m : aux) {
     Consola.escriu("Moto " + Integer.toString(i + 1));
     Consola.escriu("****************");
     m.printInfoMoto();
     Consola.escriu("****************");
     i++;
   }
 }
Ejemplo n.º 2
0
  /** Method that allows the admin to see all the motos. */
  private void seeMotos() {
    int i = 0;
    // Print the motos located in locals.
    for (Local l : lstLocal) {
      // First, let the admin know in which local are the motos.
      i++;
      Consola.escriu("------------");
      Consola.escriu("Local " + i);
      l.printInfoLocal();
      Consola.escriu("------------");
      // Second, lets print all the motos
      Consola.escriu("Motos being driven");
      l.printMotoList();
    }

    // Print the motos currently being driven.
    Consola.escriu("Motos currently on the road: ");
    for (Moto m : lstDriving) {
      m.printInfoMoto();
    }
  }
Ejemplo n.º 3
0
  /**
   * Prints a certain information about the book.
   *
   * @param localS
   * @param localE
   * @param motoreta
   * @param date
   * @param cantDias
   * @param cantHoras
   */
  private void bookPrintInfo(
      Local localS, Local localE, Moto motoreta, Calendar date, int cantDias, int cantHoras) {
    String strDays;
    String strHours;

    localS.printInfoLocal();
    localE.printInfoLocal();
    motoreta.printInfoMoto();

    Consola.escriu("Time to reserve");
    strDays = Integer.toString(cantDias);
    strHours = Integer.toString(cantHoras);
    Consola.escriu("Days:" + strDays + "Hours:" + strHours);
  }
Ejemplo n.º 4
0
  /** The client can book a moto if he/she hasn't an active reserve. */
  private void book() {
    boolean r = ((Client) current).hasActiveReserve();
    boolean correct = false;
    boolean check = false;
    int hours = 0;
    int days = 0;
    int month = 0;
    int year = 0;
    Calendar date = null;
    if (!r) {
      while (!correct) {
        Consola.escriu("Insert a date (hh/dd/mm/yyyy)");
        String fecha = Consola.llegeixString();
        String[] parser = fecha.split("/");
        date = Consola.llegeixDataSistema();
        try {
          hours = Integer.parseInt(parser[0]);
          days = Integer.parseInt(parser[1]);
          month = Integer.parseInt(parser[2]) - 1;
          year = Integer.parseInt(parser[3]);

          while (!check) {
            check = true;
            if (hours > 20 || hours <= 8) {
              check = false;
              Consola.escriu(
                  "The inserted hour is incorrect (8-20 hours only accepted). Please insert it again");
              hours = Consola.llegeixInt();
            }
          }
          check = false;
          while (!check) {
            check = true;
            if (days > 31 || days <= 0) {
              check = false;
              Consola.escriu("The inserted day is incorrect. Please insert it again");
              days = Consola.llegeixInt();
            }
          }
          check = false;
          while (!check) {
            check = true;
            if (month > 12 || month <= 0) {
              check = false;
              Consola.escriu("The inserted month is incorrect. Please insert it again");
              month = Consola.llegeixInt();
            }
          }
          check = false;
          while (!check) {
            check = true;
            if (year >= 2017 || year <= 0) {
              check = false;
              Consola.escriu("The inserted year is incorrect. Please insert it again");
              year = Consola.llegeixInt();
            }
          }

          date.set(year, month, days, hours, 0);
          Calendar currentDate = Consola.llegeixDataSistema();
          correct = currentDate.before(date);

          if (!correct) {
            Consola.escriu("Invalid date, insert again");
          }
        } catch (Exception ex) {
          Consola.escriu(
              "There's a invalid character in the date or an enmpy value, please, write again the date:");
        }
      }

      // Trying to get our starter local.
      Local localS = bookGetLocalS();
      // If it is different from null, then we can keep going.
      if (localS != null) {
        // We can try to get our ending local.
        Local localE = bookGetLocalE();
        // And if indeed we can reach up to an ending local, we can keep going.
        if (localE != null) {
          // We DON'T have to check the same for the motos, because it is considered that a local is
          // available
          // If it has a X amount of motos. So if we reach here, then our starting local is HAS
          // motos for sure.
          Moto motoreta = bookGetMoto(localS);

          Consola.escriu("Insert number of days you would like to reserve:");
          int cantDias = Consola.llegeixInt();
          Consola.escriu("Insert number of hours you would like to reserve:");
          int cantHoras = Consola.llegeixInt();
          this.bookPrintInfo(localS, localE, motoreta, date, cantDias, cantHoras);
          Consola.escriu("Insert an S to confirm or an N to cancel the reserve");
          String ans = Consola.llegeixString();
          correct = checkYesNo(ans);
          if (correct) {
            ((Client) current)
                .addActiveReserve(localS, localE, date, cantHoras, cantDias, motoreta);
            String code = new String();
            code =
                ((Client) current).getId()
                    + localS.getId()
                    + localE.getId()
                    + motoreta.getId()
                    + Integer.toString(cantHoras)
                    + Integer.toString(cantDias);
            code =
                code
                    + date.get(Calendar.HOUR_OF_DAY)
                    + date.get(Calendar.DAY_OF_MONTH)
                    + Integer.toString(date.get(Calendar.MONTH) + 1)
                    + date.get(Calendar.YEAR);
            ((Client) current).setCodeToActiveReserve(code);
            Consola.escriu("Code: " + code);
            Consola.escriu("The reserve has been done and saved");
          }
        }
      }
    } else {
      Consola.escriu("You have already done a reserve");
    }
  }
Ejemplo n.º 5
0
  /** The admin is allowed to switch motos between some locals. */
  private void adminMoto() {
    Moto m;
    Local lStart, lEnd;
    Boolean bool = true;
    ArrayList lstLocal;
    int size, num;
    String answer;

    /**
     * TO DO: Si las listas están vacías, hay que salir de la opción porque no se pueden mover
     * motos.
     */

    // We will do this until the admin doesn't want to move more motos.
    while (bool) {
      // From which locals can we move motos? Take them and put them in a list.
      lstLocal = getStartAvailableLocals();
      // Same error control here. If the locals are empty, we can't move anything!
      if (!lstLocal.isEmpty()) {
        Consola.escriu("\n You can move motos from these locals: ");
        printLocalList(lstLocal);
        Consola.escriu("\n Insert the number of the index of your prefered local");
        num = Consola.llegeixInt();
        size = lstLocal.size();
        // Let's check if the index inserted is correct:
        num = checkNumber(num, size);
        lStart = getLocalByIndex(lstLocal, num);

        // Obtain the moto the admin wants to move:
        Consola.escriu("\n --->These are the motos you can move: ");
        lStart.printMotoList();
        Consola.escriu("\n Insert the number of the index of the moto you want to move: ");
        num = Consola.llegeixInt();
        size = lStart.getQuantityMotos();
        // Check that the index is correct
        num = checkNumber(num, size);
        m = lStart.getMotoByIndex(num);

        // To which locals can we move motos? Take them and put them in list.
        lstLocal = getEndAvailableLocals();
        if (!lstLocal.isEmpty()) {
          Consola.escriu("\n You can move motos to these locals: ");
          printLocalList(lstLocal);
          Consola.escriu("\n Insert the number of the index of your prefered local");
          num = Consola.llegeixInt();
          size = lstLocal.size();
          // Let's check if the index inserted is correct:
          num = checkNumber(num, size);
          lEnd = getLocalByIndex(lstLocal, num);

          /** LOTS of prints!! */
          Consola.escriu("*********************");
          Consola.escriu("These are the changes you are about to do: ");
          Consola.escriu("*********************");

          Consola.escriu("\n You will move a moto from the local: ");
          lStart.printInfoLocal();

          Consola.escriu("*********************");

          Consola.escriu("\n You will move the moto: ");
          m.printInfoMoto();

          Consola.escriu("*********************");

          Consola.escriu("\n You will move the moto to the local: ");
          lEnd.printInfoLocal();

          Consola.escriu("*********************");

          Consola.escriu("Insert an S to confirm the changes or an N to discard them ");
          answer = Consola.llegeixString();
          // Let's check if the admin wants to confirm the changes.
          // If we have a true, we keep doing it.
          // If we have a false, the admin doesn't want to make changes.
          bool = checkYesNo(answer);
          if (bool) {
            changeMoto(lStart, lEnd, m);

            Consola.escriu("\n *** The change has been done correctly! ***");
            Consola.escriu("Insert an S to keep moving motos, an N otherwise");
            answer = Consola.llegeixString();
            // Same scenario here. If we have a true, the admin wants to make more changes.
            bool = checkYesNo(answer);
          }
        } else {
          Consola.escriu("Sorry, but you can't move motos right now. Your locals are almost full.");
        }
      } else {
        Consola.escriu("Sorry, but you can't move motos right now. Your locals are almost empty.");
      }
    }
  }
Ejemplo n.º 6
0
  /** Manager method. It allows the admin to recieve a moto from a client. */
  public void pickUpMoto() {
    String code, answer;
    boolean check = false;
    boolean yesNo;
    boolean yesNoDesperfecto = true;
    Client myclient = null;
    Moto m;
    Local lend;

    Consola.escriu("Insert the code");
    code = Consola.llegeixString();

    code = this.checkCode(code);

    if (!code.equals("")) {
      for (int i = 0; i <= this.lstClient.size() && !check; i++) {
        check = this.lstClient.get(i).compareCode(code);

        if (check) {
          myclient = this.lstClient.get(i);
        }
      }

      m = myclient.getMotoFromActiveReserve();
      lend = myclient.getLocalEFromActiveReserve();

      Consola.escriu("Insert a 'S' if the moto is broken, insert a 'N' otherwise");
      answer = Consola.llegeixString();

      yesNo = this.checkYesNo(answer);
      if (!yesNo) {
        Consola.escriu("Insert a 'S' to admonish a minor flaw, a 'N' otherwise");
        answer = Consola.llegeixString();

        yesNoDesperfecto = this.checkYesNo(answer);

      } else {
        m.changeStatusNonAvailable();
      }

      if (yesNoDesperfecto) {
        myclient.admonish();
      }

      myclient.printActiveReserve();

      Consola.escriu("Insert a 'S' if the moto has been returned with delay or a 'N' otherwise");

      answer = Consola.llegeixString();

      yesNo = this.checkYesNo(answer);

      if (yesNo) {
        myclient.delay();
      }
      Consola.escriu("Write 'S' to confirm or 'N' to cancel");
      answer = Consola.llegeixString();

      yesNo = this.checkYesNo(answer);

      if (yesNo) {
        this.pickUpMakeChange(m, lend);
        myclient.changeActiveToDone();

      } else {
        myclient.removeAdmonishFromActiveReserve();
        myclient.removeDelayFromActiveReserve();
        m.changeStatusAvailable();
        Consola.escriu("Cancelled");
      }
    }
  }