0

Errors: Variable a, b, h2, and h1 may not have been initialized. Like I've said, i'm new to java and only 3 days in and really dont understand why this wont work... Also, the class Pokemon I wont bother to post ebcasue it is working fine and the error really has nothing to do with it.

import java.util.Scanner;

public class Simplemon extends Pokemon {
    Simplemon(int health, int strength, int speed, int type) {
        super(health, strength, speed, type);
    }


    public static void main(String[] args) {
        int s1;
        int s2;
        int h1;
        int h2;
        int sp1;
        int sp2;
        int t1;
        int t2;
        String a;
        String b;


        Scanner one = new Scanner(System.in);
        Scanner two = new Scanner(System.in);
        Scanner three = new Scanner(System.in);
        Scanner four = new Scanner(System.in);

        Pokemon charizard = new Pokemon(100, 2, 50, 1);
        Pokemon blastoise = new Pokemon(150, 2, 150, 1);
        Pokemon venasaur = new Pokemon(300, 2, 100, 1);

        System.out.println("Hello, Welcome to Simplemon!");
        System.out.println("Player One, Please select your pokemon.");
        int x = one.nextInt();
        System.out.println("Player Two, Please select your pokemon.");
        int y = two.nextInt();


        if (x == 1) {
            s1 = charizard.strength;
            h1 = charizard.health;
            sp1 = charizard.speed;
            t1 = charizard.type;
            a = "charizard";
        } else if (x == 2) {
            s1 = blastoise.strength;
            h1 = blastoise.health;
            sp1 = blastoise.speed;
            t1 = blastoise.type;
            a = "blastoise";
        } else if (x == 3) {
            s1 = venasaur.strength;
            h1 = venasaur.health;
            sp1 = venasaur.speed;
            t1 = venasaur.type;
            a = "venasaur";
        }

        if (y == 1) {
            s2 = charizard.strength;
            h2 = charizard.health;
            sp2 = charizard.speed;
            t2 = charizard.type;
            b = "charizard";
        } else if (y == 2) {
            s2 = blastoise.strength;
            h2 = blastoise.health;
            sp2 = blastoise.speed;
            t2 = blastoise.type;
            b = "blastoise";
        } else if (y == 3) {
            s2 = venasaur.strength;
            h2 = venasaur.health;
            sp2 = venasaur.speed;
            t2 = venasaur.type;
            b = "venasaur";
        }

        System.out.println(a + " begins the fight against " + b);
        h2 = h2 - s1;

        System.out.println(a + " does " + s1 + " damage to " +
                b + " and " + b + " has " + s2 + " left.");
    }
}
Marv
  • 3,517
  • 2
  • 22
  • 47
  • A recommendation: you can shorten `int s1; int s2; int h1; int h2;` etc by separating them with commas, e.g. `int s1, s2, h1, h2;`. You can also initialize them this way with: `int s1 = 0, s2 = 0, h1 = 0, h2 = 0;`. – Majora320 Mar 13 '16 at 01:07

1 Answers1

0

You need to set the variables to some initial value.

String a = "";
String b = "";
int h1 = "";
int h2 = "";
SamTebbs33
  • 5,507
  • 3
  • 22
  • 44