-1
import java.util.Random;
import java.util.Scanner;


public class TextGame {
    public static void main(String[]args){
        //System objects
        Scanner userinput = new Scanner(System.in);
        Random Randy = new Random();

        // Enemy variables
        String[]enemies = {"Die-pods", "Cammera-man","backdropdrone","Softbox-er",};    //level 1 enemies

        if(Randy.equals("Die-pods")){
            int DiePodsHealth = 10;
            int DiePodsAttack = 20;
            int diepodsdefense = 2;
        }else if (Randy.equals("Cammera-man")){
            int CammeraManHealth = 30;
            int CammeraManAttack = 10;
            int CammeraManDefense = 5;
        }else if (Randy.equals("backdropdrone")){
            int BackDropDroneHealth = 15;
            int BackDropDroneAttack = 15;
            int BackDropDroneDefense = 1;
        }else if (Randy.equals("Softbox-er")){
            int SoftBoxersHealth = 25;
            int SoftBoxersAttack = 10;
            int SoftBoxersDefense = 5;
        }

        // Player Variables
        int Health = 100;
        int baseAttack = 20;
        int defense = 5;

        boolean running = true;
        System.out.print("Welcome to my base of operations - MR.Shutter");
        GAME:
            while(running){
                int Enemies = Randy.nextInt(enemies.length);
                System.out.println(enemies + "has appeared!");
            }
    }
}

I want to make it so the computer picks a random monster and shows up in the console. However, its giving me a lot of 'equals' between objects of inconvertible types 'Random' and 'String'. How would I go about solving this.

Robert
  • 7,394
  • 40
  • 45
  • 64
  • Please edit the question and show the complete error messages, and indicate which lines of code – OldProgrammer Mar 29 '21 at 23:14
  • 3
    Java is an object oriented programming language. Randy is a `Random` object, and the strings are `String` objects. You can't compare a `Random` object with a `String` object. – Blackgaurd Mar 29 '21 at 23:16

2 Answers2

2

I think you should use choose a random index out of your enemies array effectively choosing a random enemy.

You can choose a random index with the following line

int randIndex = Randy.nextInt(enemies.length);
LuckyBandit74
  • 417
  • 1
  • 4
  • 10
0

So, one thing you could try as I've seen in another question that's been answered is using the Random.nextInt(int) method, as seen in this answer you could use the format of this solution:

https://stackoverflow.com/a/21726085/15146457

And give it another go at execution to see if it returns a more pleasing output.