#39 Reviewing and Fixing a Customer

Companies:
CFT
Themes:
JavaJava BasicsOOPCode Review

Find the errors in the code:

class Pokupatel {
    public double money;
    SomeCurrencyExchangeService service;

    public Pokupatel(float money) {
        this.money = money;
        this.service = new SomeCurrencyExchangeService();
    }

    public void setPurchases(double money) {
        this.money = 0;
        this.money = money;
    }

    public void addSomeCoins(double coins) {
        this.money += coins;
    }

    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }

        Pokupatel other = (Pokupatel) o;
        return other.money == money;
    }

    Double transferToTheCurrency(String currency) {
        try {
            return service.transferToTheCurrency(CurrencyEnum.valueOf(currency));
        } catch (Throwable e) {
            return (double) 0;
        }
    }
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in