In: Computer Science
Please use JAVA to do this: Write a method that takes four strings as parameter. The first string should be a pokemon name, the second a pokemon type(either fire, water, or leaf, where water beats fire, fire beats leaf and leaf beats water), the third a pokemon name, and the fourth a pokemon type. The method should print out which pokemon has the advantage over the other based on their type.
Example:
Pokemon X(which is the fire type) has the advantage over Pokemon Y(which is a leaf type)
Pokemon Z(which is a water type) has the advantage over Pokemon X(which is a fire type)
Pokemon Y(which is a leaf type) has the advantage over Pokemon Z(which is a water type)
import java.util.*;
class Main {
public static void pokemon(String firstPokemon, String firstPokemonType, String secondPokemon,String secondPokemonType){
if(firstPokemonType.equals(secondPokemonType)){
System.out.println("No pokemon has any advantage over other because they are of same type");
}else if (
("Water".equals(firstPokemonType) && "Fire".equals(secondPokemonType)) ||
("Fire".equals(firstPokemonType) && "Leaf".equals(secondPokemonType)) ||
("Leaf".equals(firstPokemonType) && "Water".equals(secondPokemonType)) ) {
System.out.println("Pokemon " + firstPokemon + " which is the " + firstPokemonType + " type has the advantage over " + secondPokemon + " which is the " + secondPokemonType + " type" );
}
else{
System.out.println("Pokemon " + secondPokemon + " which is the " + secondPokemonType + " type has the advantage over " + firstPokemon + " which is the " + firstPokemonType + " type" );
}
}
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.print("Enter first Pokemon : ");
String firstPokemon= sc.nextLine();
System.out.print("Enter first Pokemon type, either Fire, Water or Leaf : ");
String firstPokemonType= sc.nextLine();
System.out.print("Enter second Pokemon : ");
String secondPokemon= sc.nextLine();
System.out.print("Enter second Pokemon type either Fire, Water or Leaf : ");
String secondPokemonType= sc.nextLine();
sc.close();
pokemon(firstPokemon, firstPokemonType, secondPokemon,secondPokemonType);
}}
Output