Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6773739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:42:13+00:00 2026-05-26T15:42:13+00:00

I have written a class to create and battle pokemon but I cannot figure

  • 0

I have written a class to create and battle pokemon but I cannot figure out how to call the battle method in the tester class in order to test the class I wrote.

My assaignment is to write and test a simulation that models a battle between two Pokemon. Each Pokemon has a health value, a strength value, and a speed value. The health, strength, and speed values are passed in to the constructor as arguments. These values must be between 1 and 300 initially and should be nonzero initially. The overall idea for the finished game is that two Pokemon will “battle” one another in the simulation, with the pokemon taking turns attacking. (The one with the highest speed value goes first each round) The attacking Pokemon’s strength will be subtracted from the “attackee’s” health.

public class Pokemon{
  private int health;
  private int strength;
  private int speed;

/**
* Constructs the pokemon
* @Require:
*    health is an integer greater than or equal to 1 but less than or equal to 300
*    strength is and integer greater than or equal to 1 but less than or equal to 300
*    speed is an integer greater than or equal to 1 but less than or equal to 300
*/
public Pokemon(int health, int strength, int speed){
  assert health >= 1;
  assert health <= 300;
  assert strength >= 1;
  assert strength <= 300;
  assert speed >= 1;
  assert speed <= 300;

  this.health = health;
  this.strength = strength;
  this.speed = speed;
}

public void battle(Pokemon pokemon1, Pokemon pokemon2){
  do{
    System.out.println(pokemon1+" begins the fight against "+pokemon2);
    pokemon2.health = pokemon2.health - pokemon1.strength;

    System.out.println(pokemon1 +" does "+ pokemon1.strength +" damage to "+
    pokemon2 +" and "+ pokemon2 +" has "+ pokemon2.health +" left.");

    pokemon1.health = pokemon1.health - pokemon2.strength;

    System.out.println(pokemon2 +" does "+ pokemon2.strength +" damage to "+ 
    pokemon1 +" and "+ pokemon1 +" has "+ pokemon1.health +" left.");

  }while(pokemon1.health >= 1 || pokemon2.health >= 1);
  if(pokemon1.health < 1)
    System.out.println(pokemon1 +" has lost the fight");
  else
    System.out.println(pokemon2 +" has lost the fight");
  }
}

Pokemon Tester

public class PokemonTester{
  private Pokemon charizard;
  private Pokemon blastoise;
  private Pokemon venusaur;

public PokemonTester(){
   charizard = new Pokemon(100,50,50);
   blastoise = new Pokemon(150,25,150);
   venusaur = new Pokemon(300,10,100);
 }

public static void main(String[] args){
  Pokemon.battle(charizard, blastoise); //will not compile
 }
}

I do realize I have not implemented the speed aspect in taking turns yet as I’m trying to just make it work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:42:13+00:00Added an answer on May 26, 2026 at 3:42 pm

    Add static to battle function, just like in main.

    Also, you cannot use charizard and blastoise in main. Non-static variables cannot be used in static functions. You need to create local variables in `main

    public static void main(String[] args){
        Pokemon charizard = new Pokemon(100,50,50);
        Pokemon blastoise = new Pokemon(150,25,150);
        Pokemon.battle(charizard, blastoise);
    }
    

    You can also create new PokemonTester and use it’s variables:

    public static void main(String[] args){
        PokemonTester tester=new PokemonTester();
        Pokemon.battle(tester.charizard, tester.blastoise);
    }
    

    You can learn more about static members here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written an apex class that will create a PDF quote and attach
I have written a class in python that implements __str__(self) but when I use
I have designed an ASP.NET page which create graphs. I have written a class
I have written a class to handle named pipe connections, and if I create
I have written this class-methods for .net 2.0 to create objects from '|'-separated strings
I have written a class using std::tr1::regex, and I don't know how to link
I have written a class that will handle internal logging in my application. Now
I have written a C# class library (DLL) and wondering the quickest way to
I have written an NHibernateSessionFactory class which holds a static Nhibernate ISessionFactory. This is
I have written a polynomial class along the lines described in SICP 2.5.3 (except

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.