Question
I need help building a GUI in java based on the code provided Must be able to: 1 vs 1 2 vs 2 ---------------------------------------------------------------------- Main.java
I need help building a GUI in java based on the code provided
Must be able to:
1 vs 1 2 vs 2
----------------------------------------------------------------------
Main.java
import project3.characters.Bear; import project3.characters.Lion; import java.util.Random;
public class Main {
public static void main(String[] args){
Bear Bear = new Bear("Black Bear"); Lion Lion = new Lion("King of the Jungle");
System.out.println(" Characters in Fight:"); System.out.println(Bear); System.out.println(Lion);
System.out.println(" Fight Started");
Random random = new Random(); int round = 1; while (Bear.isAlive() && Lion.isAlive()){ int numOfAttackByBear = random.nextInt(5); for(int i=0; i int numOfAttackByLion = random.nextInt(5); for(int i=0; i System.out.println(" Status After Round "+round+" : "); System.out.println(Bear); System.out.println(Lion); round++; } System.out.println(" Fight Finished"); if(!Bear.isAlive()){ System.out.println(" Bear is dead."); } else { System.out.println(" Lion is dead."); } } } ---------------------------------------------------------------------- Characters.java package project3.characters; public abstract class Characters { protected String name; protected int strength; protected int health; public Characters(String name) { this.name = name; } public String getName() { return name; } public int getStrenght() { return strength; } public int getHealth() { return health; } public abstract int attack(); public abstract void hit(int points); public abstract boolean isAlive(); @Override public String toString() { return "Name: " + name + ", Strength: " + strength + ", Health: " + health ; } } ---------------------------------------------------------------------- Lion.java package project3.characters; public class Lion extends Characters{ public Lion(String name) { super(name); this.health = 100; this.strength = 10; } @Override public int attack() { return strength; } @Override public void hit(int points) { this.health -= points; } @Override public boolean isAlive() { return health>=0; } @Override public String toString() { return "[ Lion, "+super.toString()+" ]"; } } ---------------------------------------------------------------------- Gorilla.java package project3.characters; public class Gorilla extends Characters{ public Gorilla(String name) { super(name); this.health = 100; this.strength = 10; } @Override public int attack() { return strength; } @Override public void hit(int points) { this.health -= points; } @Override public boolean isAlive() { return health>=0; } @Override public String toString() { return "[ Gorrilla, "+super.toString()+" ]"; } } --------------------------------------------------------------------- Bear.java package project3.characters; public class Bear extends Characters{ public Bear(String name) { super(name); this.health = 100; this.strength = 10; } @Override public int attack() { return strength; } @Override public void hit(int points) { this.health -= points; } @Override public boolean isAlive() { return health>=0; } @Override public String toString() { return "[ Bear, "+super.toString()+" ]"; } } --------------------------------------------------------------------- Hippo.java package project3.characters; public class Hippo extends Characters{ public Hippo(String name) { super(name); this.health = 100; this.strength = 10; } @Override public int attack() { return strength; } @Override public void hit(int points) { this.health -= points; } @Override public boolean isAlive() { return health>=0; } @Override public String toString() { return "[ Hippo, "+super.toString()+" ]"; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started