So i have been trying to help myself learn Japanese by making a randomizer. When I try to run this code it says there are errors but I've looked through and I can't find any. For some reason it doesn't see that the Ename
is the same as answer. they are both string variables so I don't understand why it wont work properly.
I would love to learn why it isn't working. Thank you for those more knowledgeable than me.
import java.util.Random;
import java.util.Scanner;
public class Game {
Scanner in = new Scanner(System.in);
public int enemyCount = 4; // always need to be one less than the enemy
public String Jname;//Japanese Character
public String Ename;//English Character
public static void main(String[] args)
{
new Game();
}
public Game(){
battleMainMenu();
}
public void RandomEnemy()
{
Random random = new Random();
int rnd = random.nextInt(enemyCount);
if (rnd == 0)
{
Jname= "あ";
Ename= "a";
}
else if (rnd == 1)
{
Jname ="い";
Ename ="i";
}
else if (rnd == 2)
{
Jname="う";
Ename="u";
}
else if (rnd == 3)
{
Jname="え";
Ename="e";
}
else if (rnd == 4)
{
Jname="お";
Ename="o";
}
System.out.println("\nYou walk around and encounter a "+ Jname );
}
public void battleMainMenu()
{
RandomEnemy();
System.out.println("\nTo defeat this enemy you must write "+ Jname +"'s name in english. " + Ename);// Enames here for debugging purposes
System.out.println("Your options are : 'a', 'i', 'u', 'e', 'o' ");
System.out.println("Type one of the options in lower case. ");
String answer = in.nextLine();
System.out.println(answer);
System.out.println(Ename);
if (answer == Ename)
{
System.out.println("\nCorrect!\n");
}
else
{
System.out.println("\nIncorrect!\n");
battleMainMenu();
}
}
}