I'm having a little trouble with this problem. It's simple:
I want to use defineBuyTax(6)/defineSellTax(5) to change txbuy/txsell, so I can use printTaxes and see the values in terminal. But, I'am receiving the values 0 and 0, not 6 and 5 as expected. So, basically it is not changing the values in Conversor();
I managed to fix it, creating a Conversor object to receive defineBuyTax and then manually prints it on the main function. Also, if I use System.out.print(cm.txbuy) inside the defineBuyTax method (as indicated in the code), it returns the right value.
So, what I want to know is: how can I change the variables in Conversor() so my printTaxes method do it's job correctly?
class Conversor { public double txbuy; public double txsell; public Conversor() { this.txbuy = 0; this.txsell = 0; } public Conversor defineBuyTax (double tax) { Conversor cm = new Conversor(); cm.txbuy = tax; System.out.println(cm.txbuy); return cm; } public Conversor defineSellTax (double tax) { Conversor cm = new Conversor(); cm.txsell = tax; System.out.println(cm.txsell); return cm; } void printTaxes() { System.out.println("Buy tax: "+txbuy); System.out.println("Sell tax : "+txsell); } } class Test { public static void main (String[] args) { Conversor cm = new Conversor(); cm.defineBuyTax(6.0); cm.defineSellTax(5.0); cm.printTaxes(); } }