Follow the instructions given below: Write a program that simulates the gem fusi
ID: 3793598 • Letter: F
Question
Follow the instructions given below:
Write a program that simulates the gem fusions that occur in the TV show "Steven Universe." According to the show, the following fusions occurred between the good gems and/or humans: Garnet + Pearl = Sardonyx Garnet + Amethyst = Sugilite Pearl + Amethyst = Opal Steven + Amethyst = Smoky Quartz Connie + Steven = Stevonnie With this information, write a program that asks the users for the names of two gems/humans and outputs the fusion that they create. If the user enters a combination other than the ones entered, report that there is "No known fusion." You will need: A scanner object for input Variables to store the two gems A nested if-else statement to output the appropriate fusion Use logical operators to ensure that the correct fusion is obtained for any order Use the equalsIgnoreCase method to ensure that the code recognizes the gem's name regardless of the case entered. Comments for appropriate documentation A sample of the output is shown below: Who is the first gem? Amethyst Who is the second gem? Pearl When Amethyst and Pearl fuse, they create Opal.Explanation / Answer
package chegg.fuseandgems;
import java.util.Scanner;
public class FusionCreator {
public static void main(String[] args) {
String firstGems = null;
String secondGemes = null;
Scanner scanner = null;
try {
System.out.println("Who is the first gems : ");
scanner = new Scanner(System.in);
firstGems = scanner.nextLine();
System.out.println("Who is the second gems : ");
secondGemes = scanner.nextLine();
String finalGems = FusionEnum.getFinalGemes(firstGems, secondGemes);
if (finalGems != null) {
System.out.println("When " + firstGems + "and " + secondGemes
+ "fuse,they create " + finalGems);
} else {
System.err.println("No pairing found to create gemes.");
}
System.out.println();
} finally {
scanner.close();
}
}
private enum FusionEnum {
FIRTST("Garnet", "Pearl", "Sardonyx"), SECOND("Garnet", "Amethyst",
"Sugilite"), THIRD("Pearl", "Amethyst", "Opal"), FOURTH(
"Steven", "Amethyst", "Smoky Quartz"), FIVE("Connie", "Steven",
"Stevonnie");
private String firstGems = null;
private String secondGems = null;
private String finalGems = null;
FusionEnum(String firstGems, String secondGems, String finalGems) {
this.firstGems = firstGems;
this.secondGems = secondGems;
this.finalGems = finalGems;
}
public String getFirstGems() {
return firstGems;
}
public String getSecondGems() {
return secondGems;
}
public String getFinalGems() {
return finalGems;
}
public static String getFinalGemes(String firstgems, String secondGems) {
String finalGems = null;
boolean isValuefound = false;
for (FusionEnum f : FusionEnum.values()) {
if (f.getFirstGems().equals(firstgems)) {
if (f.getSecondGems().equals(secondGems)) {
finalGems = f.getFinalGems();
isValuefound = true;
break;
}
}
}
if (!isValuefound) {
for (FusionEnum f : FusionEnum.values()) {
if (f.getSecondGems().equals(firstgems)) {
if (f.getFirstGems().equals(secondGems)) {
finalGems = f.getFinalGems();
}
}
}
}
return finalGems;
}
}
}
Outout : Output of the above progrme will be the same as it is mentioned is question.