3

I've done some research on this site about this already, however, I'm having some trouble finding something I can use. I'm trying to create a similar program to pokemon, but much much simpler and text based. Currently I'm using arrays to store the Pokemon's stats. That's working great, but when I need to print the Pokemon's name I have to manually type it out. This has worked fine, but I want to have the player battle a random Pokemon. This is my current code:

public static void main(String[] args) {
    //Declare the Pokemon to be used
    int[] Player    = {0,  0,  0,   0,  0,   0  };
    int[] Blastoise = {79, 83, 100, 85, 105, 78 };
    int[] Raichu    = {60, 90, 55,  90, 80,  110};
    int[][] Pokemon = new int[][] {Blastoise, Raichu, Player};

    Scanner input = new Scanner(System.in);

    startBattle(input, Pokemon)
}
public static String startBattle(Scanner input, int[][] Pokemon) {
        System.out.println("A wild Pokemon appeared!");
        int r = (int) (Math.random() * 1);
        System.out.println("A wild " + **POKEMON NAME** + " appeared!");
        System.out.print("What Pokemon do you choose? ");
        String userPokemon = input.next();
        return userPokemon;
    }

Where it says POKEMON NAME is where I want to have the Pokemon's name be. I know it's super difficult to get the name of an array, or add a String to an int array (I would add the name to the list[0] spot). Is there any way I could at least associate a String with one of the lists so I could call the name of that randomly selected Pokemon? Thanks!

Ella
  • 103
  • 2
  • 8

1 Answers1

6

Create a class. Give it properties that represent things that describe your real-world entity, in this case a Pokemon.

The properties at a minimum are a string representing the name and the integer array you use to describe a character.

Here's an example:

public class Pokemon {
    private String name;

    public String getName() { return this.name; }
    public void setName(String name) { this.name = name; }

    private int hp;

    public int getHP() { return this.hp; }
    public void setHP(int hp) { this.hp = hp; }

    // Repeat the pattern for all properties that describe a Pokemon
    // hp, attack, defense, special attack, special defense, and speed
}
Eric J.
  • 147,927
  • 63
  • 340
  • 553
  • 2
    dealing with stats in an array can get very tedious if you don't have them as named properties. `"wait, what was ATK? the third number or fourth?"` so i would definitely recommend this approach – ddavison Nov 20 '15 at 19:56
  • That's a good point. I'm not sure what the numbers represent, but if they are status values it is a good idea to add separate properties to the class instead of using an integer array. – Eric J. Nov 20 '15 at 19:57
  • 1
    you should give them a code example :) i think that would help. – ddavison Nov 20 '15 at 19:58
  • 1
    @EricJ. just name the fields like "HP", "Attack", "Defence" if you plan to give an example. – gonzo Nov 20 '15 at 20:00
  • The numbers are the stats, in order: hp, attack, defense, special attack, special defense, and speed. What should the class I create contain? – Ella Nov 20 '15 at 20:08