import franck.cse5910.Gold; import franck.cse5910.Currency; import javax.swing.JOptionPane; import type.lib.ToolBox; public class GoldPrice { public static void main(String[] args) { String amountAsString = JOptionPane.showInputDialog(null, "Enter the amount of gold in kilos", "The Price of Gold", JOptionPane.QUESTION_MESSAGE); double amount = Double.parseDouble(amountAsString); ToolBox.crash(amount < 0, "The amount of gold cannot be negative"); final int GRAMS_PER_KILO = 1000; double ouncePerKilo = GRAMS_PER_KILO / Gold.GRAMS_PER_TROY_OUNCE; double priceInUSD = amount * ouncePerKilo * Gold.price(); double priceInCAD = Currency.convert(priceInUSD, Currency.USD, Currency.CAD); String priceAsString = String.format("$ %,.2f", priceInCAD); String title = "The price of " + String.format("%.2f", amount) + " kilos of gold"; JOptionPane.showMessageDialog(null, priceAsString, title, JOptionPane.INFORMATION_MESSAGE); } }