Exemplo n.º 1
0
  private void getTributary() {
    while (true) {
      System.out.println("How far did you walk until you reached the next junction? (in km)");
      try {
        this.tribDistanceTraveled = Double.parseDouble(input.nextLine());
        tribRiver =
            new ConcreteRiver(this.riverName, this.tribRiverFlows, this.tribDistanceTraveled);
        // rivers.add(river);
        compositeRiver = new CompositeRiver(river, tribRiver, rivers);
        river.add(river);
      } catch (NumberFormatException e) {
        System.out.println("I didn't understand that!");
        break;
      }
      String end = isEnd();
      if (end.equals("y")) {
        System.out.println("Do you want to explore more of the main river? y/n");
        String endish = input.nextLine();
        if (end.equals("y")) {
          retrieveMainRiver();
        } else {
          System.out.println("Great!  We're done!");
          // compositeRiver = new CompositeRiver(river,river);
          compositeRiver.print();
        }
      } else {
        System.out.println(
            "That means you must be at another confluence.  What is the name the locals have given the river flowing into this one?");
        this.riverName = input.nextLine();

        while (true) {
          System.out.println(
              "How much water is flowing from that tributary into the main river?  (L/s)");
          try {
            double newRiverFlows = Double.parseDouble(input.nextLine());
            this.tribRiverFlows = Math.abs(tribRiverFlows - newRiverFlows);
            break;
          } catch (NumberFormatException e) {
            System.out.println("I didn't understand that!");
          }
        }
        mainOrTrib();
      }
    }
  }
Exemplo n.º 2
0
  /** retreiveMainRiver() Method for looping through and getting the other rivers */
  public void retrieveMainRiver() {
    while (true) {
      System.out.println("How far did you walk until you reached the next junction? (in km)");
      try {
        this.distanceTraveled = Double.parseDouble(input.nextLine());
        river = new ConcreteRiver(this.riverName, this.riverFlows, this.distanceTraveled);

        rivers.add(river);
        compositeRiver = new CompositeRiver(river, river, rivers);
        river.add(river);
      } catch (NumberFormatException e) {
        System.out.println("I didn't understand that!");
        break;
      }
      String end = isEnd();
      if (end.equals("y")) {
        System.out.println("Do you want to explore more of the Nile? (Y/n)");
        if (input.nextLine().equalsIgnoreCase("y")) {
          retrieveMainRiver();
        } else {
          System.out.println("Great!  We're done!");
          // compositeRiver = new CompositeRiver(river,river);
          compositeRiver.print();
          // river.print();
          break;
        }
      } else {
        System.out.println(
            "That means you must be at another confluence.  What is the name the locals have given the river flowing into this one?");
        this.riverName = input.nextLine();

        retrieveFlow();
        mainOrTrib();
      }
    }
  }