Using the given java code, define the following methods in the code:
1. methodOne: This method should have at least one array as a parameter and should use a multi-way if-else statement.
2. methodTwo: This method should have 2 parameters and should return an array.
3. methodThree: This method may have 0 or more parameters and should use a return statement and either one Math or String method.
4. methodFour: This method may have 0 or more parameters and should use a loop.
In the main method, explain to the user what 4 tasks your program can do. Ask the user to enter 1, 2, 3, or 4 to choose which task they want your program to do, then call the relevant function.
Your program MUST:
- Actively use in-line comments stating what each section of code does.
- Have very clear output to the user that explains what is happening in the program.
- Use try/catch if, and only if, necessary.
import java.util.Scanner;
public class DEMO
public static String translateToItalian(String word)
String[][] translations = "XXXXX", "XXXXX", "XXXXX", "XXXX";
for (String[] pair : translations)
if (pair[0].equalsIgnoreCase(word))
return pair[1];
return word;
public static String reverseString(String str)
return new StringBuilder(str).reverse().toString();
public static void printCoolestMessage()
System.out.println("XXXXXXXXXXXXXXXXX, XXXXXXXXXXXXx!");
public static void playGame()
Scanner scanner = new Scanner(System.in);
String choice;
do
System.out.println("Playing the game, XXXXX");
System.out.print("Do you want to play again? (yes/no): ");
choice = scanner.nextLine();
while (!choice.equalsIgnoreCase("no"));
public static void main(String[] args)
Scanner scanner = new Scanner(System.in);
System.out.println("Hello! What's your name?");
String name = scanner.nextLine();
System.out.println("Hi, " + name + "! Let me show you what I've learned thus far!");
System.out.println("Here are some things that this program can do:");
System.out.println("1. Translate a word from English to Italian");
System.out.println("2. Spell your name backwards!");
System.out.println("3. Print the COOLEST message you'll EVER read");
System.out.println("4. Let you play a game over and over again until you say stop");
System.out.print("Please choose one of the options (Type 1, 2, 3, or 4): ");
try
int choice = scanner.nextInt();
switch (choice)
case 1:
System.out.println("Option 1: Translate a word from English to Italian");
System.out.print("Enter a word in English: ");
scanner.nextLine(); // consume the newline character
String englishWord = scanner.nextLine();
String italianTranslation = translateToItalian(englishWord);
System.out.println("The translation of '" + englishWord + "' in Italian is '" + italianTranslation + "'.");
break;
case 2:
System.out.println("Option 2: Spell your name backwards!");
System.out.println("What a great choice!");
System.out.println("Here's your name backwards:");
String reversedName = reverseString(name);
System.out.println(reversedName);
System.out.println("HAHA, isn't that hilarious! :)");
break;
case 3:
System.out.println("Option 3: Print the COOLEST message you'll EVER read");
printCoolestMessage();
break;
case 4:
System.out.println("Option 4: Let you play a game over and over again until you say stop");
playGame();
break;
default:
System.out.println("Invalid choice. Please enter a number between 1 and 4.");
catch (Exception e)
System.out.println("Invalid input. Please enter a valid number.");
finally
scanner.close();
System.out.println("Thanks for using my program! Have a great day!");