Java Reference
In-Depth Information
public Quote(String shopName, double price, Discount.Code code) {
this.shopName = shopName;
this.price = price;
this.discountCode = code;
}
public static Quote parse(String s) {
String[] split = s.split(":");
String shopName = split[0];
double price = Double.parseDouble(split[1]);
Discount.Code discountCode = Discount.Code.valueOf(split[2]);
return new Quote(shopName, price, discountCode);
}
public String getShopName() { return shopName; }
public double getPrice() { return price; }
public Discount.Code getDiscountCode() { return discountCode; }
}
You can obtain an instance of the Quote class, which contains the name of the shop, the
nondiscounted price, and the discount code, by simply passing the String produced by a shop to
the static parse factory method.
The Discount service will also have an applyDiscount method accepting a Quote object and
returning a String stating the discounted price for the shop that produced that quote, as shown
in the next listing.
 
Search WWH ::




Custom Search