title: How can i print a method that return a refrence variable of calculation of area?
body: <p>I'm learning object and i'm trying diffrent things to learn that. I've writen 2 method one of them return's an int and it works as i want. But other one is tuffer bc i'm doing something wrong it gives strange numbers. Could you please help me how can i write Box calculateArea2?(I looked at getter and setter but we did not learn those things yet). Here is my code;</p>
  
  <pre><code> public static void main(String[] args) {
      Box box1 = new Box();
      Box box2 = new Box();
      String str = JOptionPane.showInputDialog("Enter a length and width");
      Scanner input = new Scanner(str);
  
      box1.length = input.nextInt();
      box1.width = input.nextInt();
  
      int BoxsArea = calculateArea(box1); // calculate box1
      JOptionPane.showMessageDialog(null, " First Box's area is: "+BoxsArea );
  
      String str2 = JOptionPane.showInputDialog("Enter a length and width");
      input = new Scanner(str2);
  
      box2.length = input.nextInt();
      box2.width = input.nextInt();
  
      Box box3 = new Box();
      calculateArea2(box2); // Calculate box 2
  
      JOptionPane.showMessageDialog(null, " Second Box's area is: "+box3 );
  
  }
  
  public static int calculateArea(Box k){
      return k.length* k.width;
  }
  
  
  public static Box calculateArea2(Box k){
      Box c = new Box();
      c.area = c.length*c.area;
      return c;
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>class Box{
  int length;
  int width;
  int area;
  </code></pre>
  
  <p>}</p>