introduction.message=Welcome to the adder program

input.message=The input values are {0} and {1}

result.message=The result is {0}

 

 

 

 

 

package adder;

import java.io.IOException;

import java.text.MessageFormat;

import java.util.Properties;

public class Adder {

    private Properties properties = new Properties();

    public Adder() {

        try {    

            properties.load(getClass().getResourceAsStream(

                "/messages.properties"));

            System.out.println(properties.getProperty(       

                "introduction.message"));

        } catch (IOException e) {

            e.printStackTrace(System.out);

        }

    }

     

    public void add(int a, int b) {

        String inputMessage = properties.getProperty(

            "input.message");

        String resultMessage = properties.getProperty(

            "result.message");

        System.out.println(MessageFormat.format(

            inputMessage, a, b));

        System.out.println(MessageFormat.format(

            resultMessage, a + b));

    }

 

    public static void main(String[] args) {

        Adder adder = new Adder();

        adder.add(20, 30);

        adder.add(23, 12);

    }

}

 

 

 

 

 

package adder;

import java.util.Locale;

public class MyLocale {

    public static void main(String[] args) {

        Locale l = Locale.getDefault();

        System.out.println(l.getLanguage());

        System.out.println(l.getDisplayCountry());

    }

}

 

 

 

 

 

package adder;

import java.text.MessageFormat;

import java.util.Locale;

import java.util.ResourceBundle;

public class Adder {

    private ResourceBundle resourceBundle;

    public Adder() {

        resourceBundle = ResourceBundle.getBundle("messages");

        System.out.println(resourceBundle.getString(

            "introduction.message"));

    }

    public void add(int a, int b) {

        String inputMessage = resourceBundle.getString(

            "input.message");

        String resultMessage = resourceBundle.getString(

             "result.message");

        System.out.println(MessageFormat.format(

            inputMessage, a, b));

        System.out.println(MessageFormat.format(

            resultMessage, a + b));

    }

 

    public static void main(String[] args) {

        Adder adder = new Adder();

        adder.add(20, 30);

        adder.add(23, 12);

    }

}

 

 

 

 

 

introduction.message=Bienvenue dans le programme adder

input.message=Les valeurs d'entrŽe sont {0} et {1}

result.message=Le rŽsultat est {0}

 

 

 

 

 

public Adder() {

    Locale french = new Locale.Builder()

       .setLanguage("fr")

       .setRegion("FR").build();

    resourceBundle = ResourceBundle.getBundle("messages", french);

 

 

 

 

package adder;

import java.text.NumberFormat;

import java.util.Locale;

public class Numbers {

    public static void main(String[] args) {

        NumberFormat nf = NumberFormat.getInstance(Locale.ITALY);

        System.out.println(nf.format(999999.99));

        nf = NumberFormat.getCurrencyInstance(Locale.ITALY);

        System.out.println(nf.format(999999.99));

        nf = NumberFormat.getPercentInstance(Locale.ITALY);

        System.out.println(nf.format(999999.99));

    }

}