Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the application of international e-commerce. Now you are asked to exten

ID: 3776187 • Letter: C

Question

Consider the application of international e-commerce. Now you are asked to extend that solution to deal with another aspect of doing business internationally online: depending on the location of the consumers, the system is supposed to automatically convert the price into the local currency and display it. Provide a skeleton implementation in Java. The code should be pretty close to compilable with correct Java syntax; however, it does not actually have to be ran through a Java IDK. The specifics with actual operations can be sketchy. The main emphasis is on the structure and how well the code works together (calling other methods).

Explanation / Answer

import java.text.NumberFormat;

import java.util.Currency;

import java.util.Locale;

public class NumberToCurrencyExamples

{

   public static void main(String[] args)

   {

      //This is the amount which we want to format

      Double currencyAmount = new Double(123456789.555);

       

      //Get current locale information

      Locale currentLocale = Locale.getDefault();

       

      //Get currency instance from locale; This will have all currency related information

      Currency currentCurrency = Currency.getInstance(currentLocale);

       

      //Currency Formatter specific to locale

      NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(currentLocale);

      //Test the output

      System.out.println(currentLocale.getDisplayName());

       

      System.out.println(currentCurrency.getDisplayName());

       

      System.out.println(currencyFormatter.format(currencyAmount));

   }

}