Java Reference
In-Depth Information
Intentions
—Omit the declaration of the
answer
variable, and let
IDEA
note that
answer = rate
isn't a valid line. Select
Create
Local Variable 'answer'
from the intention pop-up, and initialize
it to zero.
■
Listing 3.2
A basic implementation of a
CurrencyService
for the
ACME project
package com.acme.conversion.currency.service;
public class FixedRateCurrencyExchangeService
implements CurrencyExchangeService {
private double rate;
public FixedRateCurrencyExchangeService() {
rate = 1.5;
}
public double getRate() {
return rate;
}
public void setRate(double rate) {
this.rate = rate;
}
public double requestCurrentRate(String fromCurrency,
String toCurrency) {
double answer = 0;
if (fromCurrency.equals("USD") &&
toCurrency.equals("CDN")) {
answer = rate;
}
if (fromCurrency.equals("CDN") &&
toCurrency.equals("USD")) {
answer = 1/rate;
}
return answer;
}
}
3.10 Summary
IDEA
is a mature and sophisticated
IDE
for the Java language whose feature set
can be compared favorably against any modern editor on the market. It boasts a