title: How can you create a factory method to replace a constructor with functionality?
body: <p>I currently have a constructor that has some functionality inside. I know this can't be good. It makes it impossible to test the expected output of the method inside here. How can I change this up?</p>
  
  <pre><code>public loan(BigDecimal amount, BigDecimal interestRate, BigDecimal years) {
  
      this.amount = amount.multiply(BigDecimal.valueOf(100));
      this.interest = interestRate;
      this.initialTermMonths = years.multiply(BigDecimal.valueOf(12));
  
      this.monthlyPaymentAmount = calculateMonthlyPayment();
  }
  </code></pre>
  
  <p>There is no way for me to make a JUnit test to assert the calculateMonthlyPayment() method output. How can I change this into a factory method? Or is there another way?</p>