#304 Code Review of a Client Account Class
Perform a code review:
public class SchetClienta {
public LinkedList<Double> history;
SomeCurrencyExchangeService service;
public SchetClienta(LinkedList<Double> initial) {
this.history = initial;
this.service = new SomeCurrencyExchangeService();
}
public void setPurchases(Double money) {
history.add(money);
}
public boolean equals(Object o) {
if (this == o) {
return true;
}
SchetClienta other = (SchetClienta) o;
return history == other.history;
}
Double transferToTheCurrency(String currency) {
AtomicReference<Double> sum = new AtomicReference<>(0.0);
try {
history.forEach(it -> {
Double converted = service.getValueForCurrency(CurrencyEnum.valueOf(currency), it);
sum.accumulateAndGet(converted, Double::sum);
});
return sum.get();
} catch (Throwable t) {
return 0.0;
}
}
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor