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

I need help with this JAVA program. Objective: If you need a foreign language me

ID: 3738879 • Letter: I

Question

I need help with this JAVA program. Objective:

If you need a foreign language message and don't know that language, just flag the target language in the string. So, if you want to say "Hello" in French, and don't know "Bonjour," put "Hello (in french)" in your message value.

Using the attached program as a starter, make the following enhancements:

move the user prompt strings to a properties file

create a corresponding properties file for another language/region

query the current system Locale and display it

display the menu from your properties file

change the JVM's Locale

display the menu from your properties file (again)

Code:

MenuFromProperties:

public class MenuFromProperties {

private static final String[] TOP_MENU = { "List Library", "Sort Library By Composer", "Sort Library By Genre",

"Sort Library by Duration", "Play Playlist", "Create Playlist", "Exit" };

public static void main(String[] args) throws InterruptedException, URISyntaxException, FileNotFoundException,

IOException, ClassNotFoundException {

Scanner kybd = new Scanner(System.in);

int userChoice = -1;

userChoice = Utils.userChoose(kybd, TOP_MENU);

}

}

Utils:

public class Utils {

public static int userChoose(Scanner kybd, String[] choices) {

int choice = -1;

System.out.println("Make a Selection: ");

for (int i = 0; i < choices.length; i++) {

System.out.println(" [" + i + "] " + choices[i]);

}

choice = kybd.nextInt();

return choice;

}

public static int userChoose(Scanner kybd, List<String> choices) {

int choice = -1;

System.out.println("Make a Selection: ");

for (int i = 0; i < choices.size(); i++) {

System.out.println(" [" + i + "] " + choices.get(i));

}

choice = kybd.nextInt();

return choice;

}

}

Explanation / Answer

Hi friend, You have not poste Properties class, so I can not test:

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import java.net.URISyntaxException;

import java.util.Properties;

import java.util.Scanner;

public class MenuFromProperties {

   static Properties props = new Properties();

   FileInputStream is = null;

   MenuFromProperties() {

       try {

           File f = new File("menu.properties");

           is = new FileInputStream( f );

       }

       catch ( Exception e ) { is = null; }

       try {

           if ( is == null ) {

               is = (FileInputStream) getClass().getResourceAsStream("menu.properties");

           }

           // Try loading properties from the file (if found)

           props.load( is );

       }

       catch ( Exception e ) { }

   }

   private static final String TOP_MENU = props.getProperty("TOP_MENU");

   public static void main(String[] args) throws InterruptedException, URISyntaxException, FileNotFoundException,

   IOException, ClassNotFoundException {

       try {

           File f = new File("userChoice.properties");

           OutputStream out = new FileOutputStream( f );

       }

       catch (Exception e ) {

           e.printStackTrace();

       }

       Scanner kybd = new Scanner(System.in);

       int userChoice = -1;

       userChoice = Utils.userChoose(kybd, TOP_MENU,props);

   }

}

###########

import java.util.List;

import java.util.Properties;

import java.util.Scanner;

import java.io.OutputStream;

import java.util.ArrayList;

public class Utils {

   public static int userChoose(Scanner kybd, String[] choices,OutputStream out,Properties props) {

       int choice = -1;

       System.out.println("Make a Selection: ");

       for (int i = 0; i < choices.length; i++) {

           System.out.println(" [" + i + "] " + choices[i]);

       }

       choice = kybd.nextInt();

       props.store(out, choice);

       return choice;

   }

}