Question: I cannot get this code to work. Please help! //Superhero class public class SuperHero { String name; int health; boolean isDead; public SuperHero(String name, int

 I cannot get this code to work. Please help! //Superhero class

I cannot get this code to work. Please help!

//Superhero class

public class SuperHero { String name; int health; boolean isDead; public SuperHero(String name, int health) { //Initialize internal variables this.name = name; this.health = health; } public void attack(Superhero opponent) { // Create a random number between 1 and 10 Random rand = new Random(); int damage = rand.ints(1, (10 + 1)).findFirst().getAsInt(); // Set the health of the provided opponent opponent.determineHealth(damage); System.out.println(String.format("%s has damage of %d and health of %d", oppoent.name, damage, opponent.health)); } public boolean isDead() { return isDead; } private void determineHealth(int damage) { // If no more health then mark as dead else subtract damage from health and continue if(this.health - damage

===========================================

//Superman class

public class Superman extends Superhero { public Superman(int health) { super("Superman", health); } }

============================

//Batman class

public class Batman extends Superhero { public Batman(int health) { super("Batman", health); }

}

=============================

//Game class

public class Game {

public static void main(String[] args) { // Create a random health between 1 and 1000 Random rand = new Random(); int health1 = rand.ints(1, (1000 + 1)).findFirst().getAsInt(); int health2 = rand.ints(1, (1000 + 1)).findFirst().getAsInt(); // Create Superman and Batman System.out.println("Creating our Super Heroes....."); Superman superman = new Superman(health1); Batman batman = new Batman(health2); System.out.println("Super Heroes created"); // Run the game until one of the Super Heroes are dead System.out.println("Running our game....."); while(!superman.isDead() && !batman.isDead()) { // Attach each other superman.attack(batman); batman.attack(superman); // See if anybody survived if(superman.isDead()) { System.out.println("Batman defeated Superman"); } if(batman.isDead()) { System.out.println("Superman defeated Batman"); } }

}

}

::: .. RE ER LILL . TILLS SI SLANIR. RE FERRER 2. .. . PER SENSIBLE 18 - ce . . RE .....: Heal Lines

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!