I'm writing a text adventure java game and I'm having trouble calling my enemy class this is what I wrote in the enemy class: package package01; import java.util.Random; public class Enemy { private String name; private int hp; private int attackPower;    public Enemy(String name, int hp, int attackPower) { this.name = name; this.hp = hp; this.attackPower = attackPower; }     public static Enemy getRandomEnemy() { Random rand = new Random();    // Generate random attributes for the enemy String[] names = {"Zombie", "Spider", "Assassin"}; String name = names[rand.nextInt(names.length)]; int hp = rand.nextInt(100) + 1; // Random HP between 1 and 100 int attackPower = rand.nextInt(10) + 1; // R

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I'm writing a text adventure java game and I'm having trouble calling my enemy class this is what I wrote in the enemy class:

package package01;

import java.util.Random;

public class Enemy {
    
  private String name;
  private int hp;
  private int attackPower;
    
  
  public Enemy(String name, int hp, int attackPower) {
  this.name = name;
  this.hp = hp;
  this.attackPower = attackPower;
}

  
    
 public static Enemy getRandomEnemy() {
  Random rand = new Random();
  
  // Generate random attributes for the enemy
  String[] names = {"Zombie", "Spider", "Assassin"};
  String name = names[rand.nextInt(names.length)];
  int hp = rand.nextInt(100) + 1; // Random HP between 1 and 100
  int attackPower = rand.nextInt(10) + 1; // Random attack power between 1 and 10
  
  // Return a new enemy with the random attributes
  return new Enemy(name, hp, attackPower);

 

but when I try to run it in the story class I keep getting errors how can i fix this

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education