# How can I cut down on those console.?

**URL:** https://forum.codewithmosh.com/t/how-can-i-cut-down-on-those-console/15858
**Category:** Java
**Created:** [October 13, 2022, 9:13pm UTC](https://forum.codewithmosh.com/t/how-can-i-cut-down-on-those-console/15858 "2022-10-13T21:13:58Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Oriol](https://avatars.discourse-cdn.com/v4/letter/o/7cd45c/32.png) [@Oriol](https://forum.codewithmosh.com/u/Oriol)
#### Post date: [October 13, 2022, 9:13pm UTC](https://forum.codewithmosh.com/t/how-can-i-cut-down-on-those-console/15858/1 "2022-10-13T21:13:58Z")

</div>

Hey there!

I was doing the Mortgage Calculator and found out I had a very repetitive pattern on the CalculateMortgage class. Let me just show you:

```java
package me.oriol;

public class MortgageCalculator {

    private final Console console = new Console();

    public double calculateMortgage() {
        return console.principal
                * console.monthlyInterest * Math.pow(1 + console.monthlyInterest, console.numberOfPayments)
                / (Math.pow(1 + console.monthlyInterest, console.numberOfPayments) - 1);
    }

    private double calculateBalance(short numberOfPaymentsMade) {
        return console.principal
                * (Math.pow(1 + console.monthlyInterest, console.numberOfPayments)
                - Math.pow(1 + console.monthlyInterest, numberOfPaymentsMade))
                / (Math.pow(1 + console.monthlyInterest, console.numberOfPayments) - 1);
    }

    public double[] getRemainingBalances() {
        var balances = new double[console.numberOfPayments];
        for (short month = 1; month <= balances.length; month++)
            balances[month -1] = calculateBalance(month);
        return balances;
    }
}

```

As you can see, there’re lots of console. and the variable I want to use from the Console class. Is there a way to cut down on those (other than just setting 3 fields specifying each variable to a new name, that’s not what I’m looking for)?  
I’m looking for a clean solution which doesn’t need to use 3 fields in the CalculateMortgage class.

Edit: any other observation to clean the code/improve it or whatever is useful as well!

---

<div class="post-metadata">

### Author: ![jmrunkle](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jmrunkle/32/3765_2.png) [@jmrunkle](https://forum.codewithmosh.com/u/jmrunkle)
#### Post date: [October 14, 2022, 2:39am UTC](https://forum.codewithmosh.com/t/how-can-i-cut-down-on-those-console/15858/2 "2022-10-14T02:39:59Z")

</div>

We can probably resolve this over in your original post ([Any flaws on my Mortgage Calculator?](https://forum.codewithmosh.com/t/any-flaws-on-my-mortgage-calculator/15844)), but basically it looks like your Console class is not the right place to be storing those values.
