Implement a Generic Interface for One Type
easyQuestion 501The generic interface Formatter<T> turns a value of type T into text. A class that implements it can fix T to one real type, and then its format method takes exactly that type. PriceFormatter fixes it to Double and CountFormatter fixes it to Integer. Complete both format methods.
Requirements:
1. PriceFormatter.format returns the number as a price: a dollar sign followed by the number with exactly two decimals, so 4.5 becomes $4.50. String.format with the pattern "$%.2f" does this.
2. CountFormatter.format returns the number followed by a space and the word items, so 3 becomes 3 items.
3. Do not change the interface or the two class headers.
Do NOT write a main method.
Expected output
$4.50 $20.00 3 items
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...