Exemplo n.º 1
0
  public static void main(String[] args) throws CloneNotSupportedException {
    Rectangle r1 = new Rectangle();

    Rectangle r2 = (Rectangle) r1.clone();

    System.out.println(r1.toString());
    System.out.println(r2.toString());

    r1.length = 10;
    System.out.println(r1.toString());
    System.out.println(r2.toString());
    System.out.println("side of sqaure: " + r1.s1.side);
    System.out.println("side of sqaure: " + r2.s1.side);
    r1.s1.side = 20;
    System.out.println("side of sqaure: " + r1.s1.side);
    System.out.println("side of sqaure: " + r2.s1.side);
    r1.s1.side = 30;
    System.out.println("side of sqaure: " + r1.s1.side);
    System.out.println("side of sqaure: " + r2.s1.side);
  }
Exemplo n.º 2
0
  /**
   * Executes the "Rectangle" command
   *
   * @param commandList the command along with the necessary parameters specified by the user
   */
  public void executeRectangle(ArrayList<String> commandList) throws Exception {
    if (commandList.size() != 3 && commandList.size() != 5) {
      throw new Exception(
          "\nInvalid arguments, code not executed"
              + "\nCorrect Syntax: \nrectangle length width"
              + "\nrectangle X Y length width\n");
    }

    double x, y, length, width;

    if (commandList.size() == 3) {
      length = Double.parseDouble(commandList.get(1));
      width = Double.parseDouble(commandList.get(2));
      Rectangle rect = new Rectangle(length, width);
      System.out.println(rect.toString());
    } else {
      x = Double.parseDouble(commandList.get(1));
      y = Double.parseDouble(commandList.get(2));
      length = Double.parseDouble(commandList.get(3));
      width = Double.parseDouble(commandList.get(4));
      Rectangle rect = new Rectangle(x, y, length, width);
      System.out.println(rect.toString());
    }
  }