Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I make a Pokemon.java class and a PokemeonTest. Need to pass all the junit test.

ID: 3743574 • Letter: I

Question

I make a Pokemon.java class and a PokemeonTest. Need to pass all the junit test. But I am fail the toStringTest1 , 2 and 3. Don't know why.

This is part of my Pokemon.java code.

public String toString(){
DecimalFormat decimal = new DecimalFormat("000");
String string = "";
string =string + "Species: " + this.species + " ";
if(this.species.compareTo(this.name) != 0){
string =string + "Name: " +this.name + " ";
}
string =string + "Number: " + decimal.format(this.number) + " ";
string =string + "Type: " + this.type1;
if(this.type2.length() > 0){
string = string + " | " + this.type2;
}
string =string + " ";
string =string + "HP: " + this.hitPnts + " ";
string =string + "CP: " +this.comPwr +" ";
return string;
}

And This is part of the PokemonTest.java code.

@Test
public void toStringTest1(){
Pokemon p = new Pokemon("Bulbasaur", 1, "Grass", "Poison");
int hP = p.getHitPnts();
int cP = p.getComPwr();
Assert.assertEquals("toString format is incorrect for Pokemon with no name",
"Species: Bulbasaur Number: 001 Type: Grass | Poison HP: "+hP+" CP: "+cP, p.toString());

}

/* testing toString method
* checks that toString is properly formatted with Name and empty type2.
*/
@Test
public void toStringTest2(){
Pokemon p = new Pokemon("Charmander", "Lisa's Charmander", 4, "Fire", "");
int hP = p.getHitPnts();
int cP = p.getComPwr();
Assert.assertEquals("toString format is incorrect for Pokemon with name, no type 2",
"Species: Charmander Name: Lisa's Charmander Number: 004 Type: Fire HP: "+hP+" CP: "+cP, p.toString());

}
/* testing toString method
* checks that toString is properly formatted with no Name and empty type2.
*/
@Test
public void toStringTest3(){
Pokemon p = new Pokemon("Caterpie", 10, "Bug", "");
int hP = p.getHitPnts();
int cP = p.getComPwr();
Assert.assertEquals("toString format is incorrect for Pokemon with no name, no type 2",
"Species: Caterpie Number: 010 Type: Bug HP: "+hP+" CP: "+cP, p.toString());

}

JUnit: File: PokemonTest.iava X 15 tests 12 passed 3 failed (0.325 s) Testing Complete XPokemonTest 15 tests 12 passed 3 failed (0.325 s) hpRangeTest passed (0.107 s) getSpeciesTest passed(« 1 ms) noNameTest passed (1 ms) PokemonTest.toStringTest1 orgjunit.ComparisonFailure: toString format is incorrect for Pokemon with no name expected:

Explanation / Answer

In the results, It expects CP to end with a pipe character "|",(CP:140|), but your output is missing that .

That looks to be the source of mismatch

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote