<<< The "setter" and "getter" methods | Index | A custom constructor >>> |
import java.text.NumberFormat;
public class Product { // the instance variables private String code; private String description; private double price; // a custom method for returning user-friendly price public String getFormattedPrice() { NumberFormat currency = NumberFormat.getCurrencyInstance(); return currency.format(price); } }
<<< The "setter" and "getter" methods | Index | A custom constructor >>> |