In: Computer Science
Assignment Content
Resource:
For this assignment, you will develop Java™ code that relies on localization to format currencies and dates.
In NetBeans, copy the linked code to a file named "Startercode.java".
Read through the code carefully and replace all occurrences of "___?___" with Java™ code.
Note: Refer to "Working with Dates and Times" in Ch. 5, "Dates, Strings, and Localization," in OCP: Oracle® Certified Professional Java® SE 8 Programmer II Study Guide for help.
Run and debug your JAVA file to ensure that your solution works.
************************ CODE *****************************
package code;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Currency;
import java.util.Date;
import java.util.__?__;
public class Startercode {
public static void main(String[] args) {
long number = 5000000L;
NumberFormat numberFormatDefault =
NumberFormat.getInstance();
System.out.println("Number Format using Default Locale:
"+numberFormatDefault.format(number));
NumberFormat numberFormatLocale =
NumberFormat.getInstance(Locale.__?__);
System.out.println("Number Format using _?__Locale:
"+numberFormatLocale.format(number));
NumberFormat numberFormatDefaultCurrency =
NumberFormat.getCurrencyInstance();
System.out.println("Currency Format using Default __?__:
"+numberFormatDefaultCurrency.format(number));
NumberFormat numberFormatLocaleCurrency = NumberFormat.getCurrencyInstance(Locale.__?_);
System.out.println("Currency Format using __?__ Locale: "+numberFormatLocaleCurrency.format(number));
Currency currency = Currency.getInstance(L___? . ___?__);
System.out.println(currency.getDisplayName()+"
("+currency.getCurrencyCode()+")
"+currency.getDisplayName());
Date currentDate = new Date();
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL,
Locale.__?__);
System.out.println("Date Format in __?__ Locale:
"+dateFormat.format(currentDate));
}
}
package code;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Currency;
import java.util.Date;
import java.util.Locale; //import the Locale library
public class Startercode {
public static void main(String[] args) {
long number = 5000000L;
NumberFormat numberFormatDefault = NumberFormat.getInstance(); // gets the default locale format
System.out.println("Number Format using Default Locale: "+numberFormatDefault.format(number));
NumberFormat numberFormatLocale = NumberFormat.getInstance(Locale.US); // returns the number format in US locale
System.out.println("Number Format using US Locale: "+numberFormatLocale.format(number));
NumberFormat numberFormatDefaultCurrency = NumberFormat.getCurrencyInstance(); // get the currency format in default locale
System.out.println("Currency Format using Default Locale : "+numberFormatDefaultCurrency.format(number));
NumberFormat numberFormatLocaleCurrency = NumberFormat.getCurrencyInstance(Locale.US); // get the currency format in US locale
System.out.println("Currency Format using US Locale: "+numberFormatLocaleCurrency.format(number));
Currency currency = Currency.getInstance(Locale.US); // returns the currency instance for given locale
System.out.println(currency.getDisplayName()+" ("+currency.getCurrencyCode()+")"+currency.getDisplayName());
Date currentDate = new Date();
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL, Locale.getDefault()); // get the date instance for default locale
System.out.println("Date Format in Default Locale: "+dateFormat.format(currentDate));
}
}
//end of program
Output: