So I am making a plugin for a Minecraft server and I had to get my command command argument from one class to another and After trying multiple things, I started using an ArrayList, It worked for the most part but it put brackets around
the argument.
ArrayList<String> target = Main.target;
#EventHandler
public void invClickEvent(InventoryClickEvent e) {
Inventory inv = e.getInventory();
Player player = (Player) e.getWhoClicked();
String name = inv.getName();
if ( name.equals(ChatColor.RED + "Ban Menu")) {
e.setCancelled(true);
int slot = e.getSlot();
if (slot < 0)
{
return;
}
if (slot == 0)
{
player.performCommand("kill " + target);
player.closeInventory();
return;
}
That is the code that is giving me troubles. It is pulling the data from my main class. It the ArrayList is pulling text from an argument.
public static ArrayList<String> target = new ArrayList<String>();
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player && args.length == 1)
{
Player p = (Player) sender;
if (args.length > 0) {
switch (args.length)
{
case 1:
Player player = Bukkit.getPlayer(args[0]);
if (player == null) {
sender.sendMessage("That player is not online");
} else if (player.isOnline()) {
Menus.openMenu(p);
target.add(player.getPlayerListName());
}
That is where the array is pulling the argument. The output would be something like player executed command: /kill [HoloPanio] and I want it to output player executed command: /kill HoloPanio
If there is another method to import the arguments please let me know, if not then please tell me how to fix this issue.
Thanks!
Just expanding on what Titus has said in their comment.
Instead of using ArrayList, try using a String as the type for target. This will allow the output to be player executed command: /kill HoloPanio.
String target = Main.target;
#EventHandler
public void invClickEvent(InventoryClickEvent e) {
Inventory inv = e.getInventory();
Player player = (Player) e.getWhoClicked();
String name = inv.getName();
if ( name.equals(ChatColor.RED + "Ban Menu")) {
e.setCancelled(true);
int slot = e.getSlot();
if (slot < 0)
{
return;
}
if (slot == 0)
{
player.performCommand("kill " + target);
player.closeInventory();
return;
}
The below would be updated to initial target as an empty String. Note that a static variable will be updated for every user of this class. This means that any other code accessing this class will have the same target. And, any other code accessing this class can change the target.
public static String target = "";
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player && args.length == 1)
{
Player p = (Player) sender;
if (args.length > 0) {
switch (args.length)
{
case 1:
Player player = Bukkit.getPlayer(args[0]);
if (player == null) {
sender.sendMessage("That player is not online");
} else if (player.isOnline()) {
Menus.openMenu(p);
target = player.getPlayerListName();
}
Also as Titus said, this is not the best solution because, as a static variable, the target will likely change when you don't want it to (or will end up being the same when you want it to change). But, this should solve the command issue.
This is default ArrayList toString.
Use to String.join to remove the brackets
String result = String.join("", list);
This is because of toString method of ArrayList class.
Extends the ArryList class and override the toString
ArrayList<String> list = new ArrayList<String>()
{
private static final long serialVersionUID = 1L;
#Override public String toString()
{
return super.toString().substring(1,super.toString().length-1) ;
}
};
Speaking absolutely nothing to the Minecraft angle, if you wanted to get the list of elements back and not have to print the collection, you could aggregate it with a StringJoiner instead.
String values = String.join(",", target);
System.out.println(values);
Related
I'm trying to implement a monopoly-style game in java as part of a school project but I've run into an issue that I cant resolve or seem to find an answer to the question that I have. The problem is that I'm getting a classCastException in my code, I think I've figured out why I'm getting it (i was originally trying to cast type Property onto the newPosition variable below)but now I need to find a way to implement the code so that I can avoid it.
The issue is i have a superclass Square which has 3 possible subclasses Property, Go and FreeParking. I'm storing my board as an ArrayList but I need to access the methods pertaining to Property objects to calculate rent etc. How can I access these methods if when I access the property from the ArrayList it it of type Square.
Apologies in advance if this doesn't make too much sense.
public abstract class Square {
private String name;
private boolean isAvailable;
private Player owner;
//getters and setters
}
public class Property extends Square{
private String colour;
private int buyHouset;
private int rent1House;
private int rent2House;
private int rent3House;
private int rentHotel;
private int numHouses;
private int rent;
private int price;
//getters and setters
}
public static void takeTurn(Player player, Dice die, ArrayList<Square> board) {
System.out.println(player.getGamertag() + "'s turn");
//get value from roll of die
int move = askToRoll();
String gamertag = player.getGamertag();
//if player does not quit continue with turn
if(move > 0) {
//get player current position and add roll of die
int newSpaceIndex = player.getPosition() + move;
//if players new position exceeds the array of squares, return to 0 index and add remainder
//add credits for passing Go
//else update position
if (newSpaceIndex > 11) {
player.setPosition(newSpaceIndex - 12);
Go.passGoAction(player);
}else {
player.setPosition(newSpaceIndex);
}
if(player.getPosition() == 1) {
Square newPosition = board.get(player.getPosition());
System.out.println(gamertag + " new position " + newPosition.getName());
}else if(player.getPosition() == 6) {
FreeParking.freeParkingAction();
} else {
Square newPosition = board.get(player.getPosition());
System.out.println("____________________");
System.out.println("Land on " + newPosition.getName());
if(newPosition.getOwner() != null) {
Player owner = newPosition.getOwner();
/* *****THIS IS WHERE THE ERROR IS STEMING FROM*****
*THE newPosition.getRent() method can not be accessed as newPosition
*is defines as Square
*/
System.out.println(owner.getGamertag() + " demands you pay " + newPosition.getRent() + " credits!");
}else {
System.out.println("What would you like to do now? ...\n"
+ "1. Buy property\n"
+ "2. End turn");
int input = in.nextInt();
boolean valid = false;
do {
switch(input) {
case 1:
System.out.println("You now own controlling stock of " + newPosition.getName());
player.setOwnsProperty(newPosition);
newPosition.setOwner(player);
valid = true;
break;
case 2:
System.out.println("Ending turn");
valid=true;
break;
default:
System.out.println("Invalid input, please select one of the options 1-2");
valid = false;
break;
}
}while(!valid);
}
}
}
System.out.println("END TURN: " + player);
System.out.println();
}
If you know that a particular Square is a Property, cast it and assign it to the appropriate type.
Property newPosition = (Property)board.get(player.getPosition());
Edit: In future, you might also want to consider putting the logic that goes with a particular type of Square into a subclass. In other words, something like square.process(player), where Property, Go, and FreeParking each implements the process(player) method with appropriate logic. That goes into more detailed concepts around object-oriented design, and may not be relevant to you right now.
I hope that this snippet helps you to understand the concept
public static void main(String[] args) {
Square newPosition = new Property();
if (newPosition instanceof Property) {
System.out.println("newPosition cast as Property");
Property newPositionAsProperty = ((Property) newPosition);
int newRent = newPositionAsProperty.getRent();
// or
newRent = ((Property) newPosition).getRent();
}
// To understand better
if (newPosition instanceof Square) {
System.out.println("newPosition instanceof Square");
((Square)newPosition).getName();
}
if (Square.class.isAssignableFrom(Property.class)) {
System.out.println("Square.class.isAssignableFrom(Property.class)");
((Square)newPosition).getName();
}
if (Property.class.isInstance(newPosition)) {
System.out.println("Property.class.isInstance(newPosition)");
((Property)newPosition).getName();
}
if (Square.class.isInstance(newPosition)) {
System.out.println("Square.class.isInstance(newPosition)");
((Square)newPosition).getName();
}
}
Result:
newPosition cast as Property
newPosition instanceof Square
Square.class.isAssignableFrom(Property.class)
Property.class.isInstance(newPosition)
Square.class.isInstance(newPosition)
So as the title says im struggling to add a value to an integer and then pass it to another class that uses it, then this class will pass it to the next and then that one will pass it over to the main class. Its an integer that changes the stat template of the enemies in my small game im writing.
I have tried to make constructors in two of my classes as I thought that was the problem, Ive tried to see if they work by passing some messages in them.
The problem seems to be that when I save something in the "private int l" It dosnt actually change the value of that int and I cant figure out why that is.
Here is my code, its probably not very pretty so if you have any suggestions to structure changes that I might wanna do please feel free too let me know!
Thanks in advance!
import java.util.Scanner;
public class Stor {
public static void main(String[] args) {
Scanner user_Input = new Scanner(System.in);
Menu user = new Menu();
EnemyValue monster = new EnemyValue();
user.namn();
user.AnvNamn = user_Input.next();
user.introMeny();
user.difficulty();
System.out.println(“Your enemy has " + monster.HP + " HP and " +
monster.DMG + " Damage" );
user_Input.close();
}
}
class Menu {
Scanner user_Input = new Scanner(System.in);
String AnvNamn;
String difficultySvar;
String nivåSvar;
int svar;
private int i; /
private int l;
public int getL() {
return l;
}
boolean difficultyLoop = true;
boolean felLoop = true;
void introMeny() {
System.out.println(“Welcome " + AnvNamn + "!");
}
void namn() {
System.out.print(“Pick a name: “);
}
void difficulty() {
do {
System.out.println("\nWhat level do you want ?\n1 = Easy.\n2 =
Medium.\n3 = Hard.”);
svar = user_Input.nextInt();
if (svar == 1) {
System.out.println(“Your not very brave are you ? Are you sure
this is how you wanna play ?”);
difficultySvar = user_Input.next();
if (difficultySvar.equalsIgnoreCase(“Yes”)) {
difficultyLoop = false;
l = 1;
} // If ja 1
else if (difficultySvar.equalsIgnoreCase(“Nej”)) {
System.out.println(“Ahh good! I figuerd you would change
your mind.”);
}
else
System.out.println(“I don’t understand….”);
} // if 1
else if (svar == 2) {
System.out.println(“Not to hard or to easy, a good choice! But
maybe you want to go for something harder ? Or maybe easier ?");
difficultySvar = user_Input.next();
if (difficultySvar.equalsIgnoreCase(“Yes”)) {
difficultyLoop = false;
l = 2;
} // if ja 2
else if (difficultySvar.equalsIgnoreCase(“No”)) {
System.out.println(“I sure hope you don’t pick the easy
way…..”);
}
else
System.out.println("I don’t understand….");
} // Else if 2
else if (svar == 3) {
System.out.println(“Damn! We have a big player here! Are you
sure you can handle this ?");
difficultySvar = user_Input.next();
if (difficultySvar.equalsIgnoreCase(“Yes”)) {
difficultyLoop = false;
l = 3;
} // If ja 3
else if (difficultySvar.equalsIgnoreCase(“No”)) {
System.out.println(“Wuss.”);
}
else
System.out.println(“I don’t understand….”);
} // Else if 3
else {
if (i == 0) {
System.out.println(“Ha you thought you could fool the system?!
The system fools you!”);
System.out.println(“Nah but seriously, you can only choose
between 1-3…..“);
i++;
} // if i 0
else if (i == 1) {
System.out.println(“Alright I get that its hard but
COMEON!”);
i++;
} // if i 1
else if (i == 2) {
System.out.println(“OKEY YOU GET ONE LAST CHANCE!!”);
i++;
} // if i 2
else if (i == 3) {
System.out.println(“Alright thats it…. GET OUT!”);
System.exit(0);
} // if i 3
} // Else
} // do while loop
while(difficultyLoop == true);
} //Difficulty metod.
} // Menu class.
class Nivå {
//Menu level = new Menu();
//int levelChoice = level.getL();
int levelChoice;
private int enemyLife;
public int getenemyLife() {
return enemyLife;
}
private int enemyDMG;
public int getenemyDMG() {
return enemyDMG;
}
Nivå(){
Menu level = new Menu();
levelChoice = level.getL();
System.out.println("testNivå");
}
void fiendeLiv() {
if (levelChoice == 1)
enemyLife = 100;
else if (levelChoice == 2)
enemyLife = 150;
else if (levelChoice == 3)
enemyLife = 200;
} // fiendeliv method
void fiendeDMG() {
if (levelChoice == 1)
enemyDMG = 5;
else if (levelChoice == 2)
enemyDMG = 10;
else if (levelChoice == 3)
enemyDMG = 15;
} // fiendeDMG method
} // Nivå class
class EnemyValue {
public int HP;
public int DMG;
int maxLife;
int maxDMG;
EnemyValue(){
Nivå stats = new Nivå();
maxLife = stats.getenemyLife();
maxDMG = stats.getenemyDMG();
System.out.println("TestEnemyValue");
}
void rank1() {
HP = maxLife;
DMG = maxDMG;
} // rank1 easy method
} // EnemyValue class
You say that when you save something in l (poor choice of a variable name, by the way) it does not save the value. How do you know that? Where in the code do you check whether the value is saved?
In the constructor for class Nivå you create a new Menu and then call getL() on that menu before you have ever set the value of that variable.
Everything runs at the start of your public static void main(String[] args) method, and nothing will run if its instructions are not in there. For example, you are not actually creating any Niva objects in the main method, so the Niva constructor is never called. That is one issue. The other is your constructors are creating new instances of objects and then getting their values; this gives you empty values from a brand new object:
Nivå(){
Menu level = new Menu(); // Don't do this. This is an empty menu
levelChoice = level.getL(); // Getting the blank L value from the empty menu
System.out.println("testNivå");
}
Instead, you need to define constructors with parameters to pass the values into the class like this:
Nivå(int level){ // add an int parameter
levelChoice = level; // Direct assignment
fiendeDMG(); // Call this in the constructor to set up your last value
System.out.println("testNivå");
}
Then, when you call the constructor (which you must if you want it to exist), include the parameter. Inside the Stor class:
public static void main(String[] args) {
Scanner user_Input = new Scanner(System.in);
Menu user = new Menu();
user.namn();
user.AnvNamn = user_Input.next();
user.introMeny();
user.difficulty(); // Run this before creating the other classes; you need the l value
Nivå niva = new Nivå(user.getL()); // Creates new Niva while also assigning l to the levelChoice and then getting DMG
EnemyValue monster = new EnemyValue(/*add some parameters for life and dmg*/);
}
There is still more that needs to be done, like modifying the constructor of the EnemyLevel. Just remember that methods are never called unless they connect to something running from main and use parameters in functions and constructors to pass on data to other objects. Hope this helps.
I'm a beginner when it comes to Java and I'm trying to find a way to see if an object is located on certain coordinates. I've tried to search for similar questions, but I still haven't found an answer.
The program I'm working on is a map (image file) and the user should be able to create places and place them on the map (which will be displayed as triangles on the map). There is also this function where the user should be able to type in coordinates to see if there already is a place on those coordinates.
The object is an object of the class "Place" and consists a name, an x-coordinate and an y-coordinate.
Here is my code:
class CoordinatesListener implements ActionListener {
public void actionPerformed(ActionEvent ave) {
try {
CoordinatesForm c = new CoordinatesForm();
int answer = c.getAnswer();
if (answer != JOptionPane.OK_OPTION) {
return;
}
if (c.getPosition() == null) {
JOptionPane.showMessageDialog(null, "Invalid Input kkk", "Invalid Input", JOptionPane.ERROR_MESSAGE);
} else {
Position p = c.getPosition();
boolean flag = false;
for (Position key : positionList.keySet()) {
if (key.getXCoordinate() == p.getXCoordinate() && key.getYCoordinate() == p.getYCoordinate()) {
flag = true;
this.setAllMarkedPlacesUnMarked();
Place place = positionList.get(key);
if (place != null) {
System.out.println("the place " + place + "against position " + key);
place.setMarked(true);
if (!place.isVisible()) {
place.setVisible(true);
}
markedPlacesHashMap.put(place.getName(), place);
if (markedPlacesHashMap.containsKey(place.getName())) {
markedPlacesHashMap.get(place.getName()).add(place);
} else {
// ArrayList<Place> newMarkedPlaces = new ArrayList<>();
// newMarkedPlaces.add(place);
markedPlacesHashMap.put(place.getName(), place);
}
}
}
}
Also, when a place is created, the user shouldn't be able to place another place on the same coordinates. There should be an error message saying that a place already exists on those coordinates.
Here is the code where a place is created:
private void createNamedPlace(int x, int y, String answer) {
Position pos = new Position(x, y);
display.add(n = new NamedPlace(selectedCategory, pos, answer));
p = n;
places = new ArrayList<>();
placeByCategory = new ArrayList<>();
positionList.put(pos, n);
if (categoryMap.containsKey(selectedCategory)) {
categoryMap.get(selectedCategory).add(n);
if (nameList.containsKey(answer)) {
nameList.get(answer).add(n);
} else {
places.add(n);
nameList.put(answer, places);
}
} else {
placeByCategory.add(n);
categoryMap.put(selectedCategory, placeByCategory);
if (nameList.containsKey(answer)) {
nameList.get(answer).add(n);
System.out.println("The new Place have been added in the Name
List, the place name is :" + answer);
this.displayMap(nameList, " PlACES LIST BY NAME");
} else {
places.add(n);
nameList.put(answer, places);
this.displayMap(nameList, "PLACES LIST BY NAME");
}
this.displayMap(categoryMap, " PlACES LIST BY CATEGORY");
}
n.addMouseListener(new TriangleListener());
display.validate();
display.repaint();
display.removeMouseListener(mouseListener);
display.setCursor(Cursor.getDefaultCursor());
newButton.setEnabled(true);
categoryList.clearSelection();
isSaved = false;
}
All Swing components are ultimately derived from the Component class, which has a method getBounds(), returning a rectangle. So you can simply write something like
if (myComponent.getBounds().contains(x,y)) {
// do something
where x and y are the co-ordinates of the point you're trying to check.
In my text-adventure game one of the commands is "take" which requires the user to enter both the letter 'T' and an item that is in the room they are in.
I have taken this input and split it into command and item, but I'm having trouble with the if statement. I have the first part that checks if the command section is equal to 'T', but I have to also check if this input has an "item" section to it. I tried using .isEmpty() and != null as well as using .contains().
Here is my code:
public Command getCommandFromResponse(String response) throws IllegalArgumentException{
String[] split = response.split(" ");
if (split.length < 1){
throw new IllegalArgumentException("Invalid command.");
}
Command command = new Command(split[0]);
if (split.length >= 2) {
command.setItem(split[1]);
}
return command;
}
This is the take method:
else if(userCommand.command.equalsIgnoreCase("T") && /*if userCommand contains an item*/){
//Split the input String into two parts, command and item
userCommand = getCommandFromResponse(userInput.nextLine());
if (locale.item != null) {
if (userCommand.item.equalsIgnoreCase(locale.item.itemName)) {
//add the item to the player's inventory
player1.inventory.add(locale.item);
System.out.println("\tA " + locale.item + " was added to your inventory");
System.out.println("\n\tYou can view your inventory by pressing 'I' or drop an item by pressing 'D'.");
if (locale.item.itemName.equals("map")) {
System.out.println("\n\tTo view the map press 'M'.");
}
//Add the item's worth to the score and set the items worth to zero to prevent double scoring
player1.score += locale.item.value;
System.out.println("\n\t" + locale.item.value + " points have been added to your score.");
System.out.println("\n\tThis is your current score: "+player1.score);
//remove the item from the current location
locale.item = null;
break;
} else {
System.out.println("\n\tThat item is not at this location.");
}
} else {
System.out.println("\n\tThere is no item to pick up here");
}
}//End of Take
This is my Command class:
public class Command {
String command;
String item;
public Command(String comm){
command = comm;
}
public Command(String comm, String item){
this.command = comm;
this.item = item;
}
public void setCommand(String command){
this.command = command;
}
public void setItem(String item){
this.item = item;
}
public String getCommand(){
return this.command;
}
public String getItem(){
return this.item;
}
public String toString(){
return this.command + ":" + this.item;
}
}
These are my items:
//Items {itemName, itemDes}
static Item[] items = {
new Item ("map","a layout of your house", 10 ),
new Item ("battery", "a double A battery", 5),
new Item ("flashlight", "a small silver flashlight", 10),
new Item ("key", "this unlocks some door in your house", 15),
};
I have more code if this is unclear.
My suggestion is to do it the following way:
change
if (userCommand.item.equalsIgnoreCase(locale.item.itemName)) {
to
if (userCommand.item!=null && userCommand.item.equalsIgnoreCase(locale.item.itemName)) {
This is the simplest way, which won't throw an exception if there was no item in the command.
(I'm sorry if this was not your question, but this is the problem what I think you mean.)
I have downloaded a java file needed for a coursework at college. However I find it impossible to run it. Eclipse won't give me the chance to even run it (only ant build), and if I use netbeans I get this exception :
Exception in thread "main"
java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable source code - class Hangman is public, should be declared in a file named Hangman.java
at Hangman. < clinit > (hangman(Case Conflict).java: 20)
Java Result: 1
If someone is kind enough to read through the code, I really do not know what to do next. I figure there has to be something wrong with the main class. Thanks!
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
class Hangman {
Scanner userInput;
private Set < Character > wrongGuesses;
private String[] answers = {
"leverets", "hatchlings", "puppies",
"kittens", "pullets", "goslings"
};
private String answer;
private String guessed;
private int maxTurns;
private int currentTurns;
private boolean inProgress;
private char nextGuess;
private boolean gameWin;
public Hangman() {
userInput = new Scanner(System.in);
wrongGuesses = new HashSet < Character > ();
inProgress = false;
gameWin = false;
maxTurns = 14;
currentTurns = 0;
// set answer somehow
answer = answers[0];
// set guessed to the correct number of dashes
StringBuilder sb = new StringBuilder();
for (int i = 0; i < answer.length(); i++) {
sb.append('-');
}
guessed = sb.toString();
}
/* start a new game */
public void startGame() {
inProgress = true;
startGameLoop();
}
/* the game loop. this method is the heart of the game */
private void startGameLoop() {
printInstructions();
while (inProgress) {
printStatus();
acceptGuess();
checkStatus();
}
printWinOrLose();
}
private void printInstructions() {
System.out
.println("Guess the word one letter at a time until you win or run out of turns. Good luck!");
}
private void printWinOrLose() {
if (gameWin) {
System.out.println("You win! The answer was " + answer);
} else {
System.out.println("You lose.");
}
}
private void printStatus() {
System.out.println("Guesses left: " + (maxTurns - currentTurns));
System.out.println("Current status: " + guessed);
System.out.println("Wrong guesses: " + getWrongAnswers());
}
/* get the next character from the player */
private void acceptGuess() {
System.out.println("Next guess: ");
String temp = userInput.next();
nextGuess = temp.charAt(0);
}
/* check what state the game is in */
private void checkStatus() {
// if already guessed, say already guessed.
if (wrongGuesses.contains(nextGuess)) {
System.out.println("You already guessed that!");
return;
}
// if guess is not in answer, update number of turns played and add
// guess to wrong guesses
// otherwise update the guessed variable
if (answer.indexOf(nextGuess) < 0) {
++currentTurns;
wrongGuesses.add(nextGuess);
} else {
updateGuessStatus();
}
// check to see if the player has won or lost
if (answer.equals(guessed)) {
gameWin = true;
inProgress = false;
}
if (currentTurns == maxTurns) {
inProgress = false;
}
}
/* update the guessed variable when there is a correct guess made */
private void updateGuessStatus() {
// replace - with nextGuess where appropriate
int index = answer.indexOf(nextGuess);
int lastIndex = answer.lastIndexOf(nextGuess);
StringBuilder sb = new StringBuilder(guessed);
if (index != lastIndex) { // more than one instance of the guess in the
// answer
// swap out in a loop
while (index != -1) {
sb.setCharAt(index, nextGuess);
int i = answer.indexOf(nextGuess, (index + 1));
index = i;
}
} else { // letter only appears once
// swap out just that one
sb.setCharAt(index, nextGuess);
}
guessed = sb.toString();
}
/* build a text representation of all the incorrect guesses */
private String getWrongAnswers() {
if (wrongGuesses.size() > 0) {
StringBuilder sb = new StringBuilder();
sb.append('(');
for (Character c: wrongGuesses) {
sb.append(c + ",");
}
sb.deleteCharAt(sb.length() - 1); // delete trailing comma
sb.append(')');
return sb.toString();
} else {
return "<none>";
}
}
public static void main(String[] args) {
Hangman h = new Hangman();
h.startGame();
}
}
The exception says everything you need to know. Rename the class FILE to Hangman.java.
Caused by: java.lang.RuntimeException: Uncompilable source code - class Hangman is public, should be declared in a file named Hangman.java
You should save your downloaded file in Hangman.java and not hangman.java (see it needs 'H' in caps same as your class name).
Change the class to public class Hangman. It allows outside methods to access it.
EDIT: I downloaded the file, changing the class to public worked. I also found an issue in the code itself, the word is always "Leverets".
To change this, edit the getAnswer() method and change it to
private int getAnswer() {
int i = (int) (Math.random() * 6) + 0;
return i;
}