Question

In: Computer Science

Please use JAVA to do this: Write a method that takes four strings as parameter. The...

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)

Solutions

Expert Solution

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


Related Solutions

Java 1.Write a method removeEvenLength that takes an ArrayList of Strings as a parameter and that...
Java 1.Write a method removeEvenLength that takes an ArrayList of Strings as a parameter and that removes all of the strings of even length from the list. 2. Given the following Vehicle interface and client program in the Car class: public interface Vehicle{ public void move(); } public class Car implements Vehicle{ public static void main(String args[]) Vehicle v = new Vehicle(); // vehicle declaration } The above declaration is valid? True or False? 3. Java permits a class to...
Write a method that takes four strings as parameter. The first string should be a pokemon...
Write a method that takes four strings as parameter. The first string should be a pokemon name, the second a pokemon type, 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. In this case you can use fire, water, and leaf. Example outputs should be like: Example: Pokemon X (Water) has the advantage over Pokemon Y (fire) Pokemon X (Fire) has...
write a java code, please do not use method and demo Consider a four digit number...
write a java code, please do not use method and demo Consider a four digit number such as 6587. Split it at two digits, as 65 and 87. Sum of 65 and 87 is 152. Sum of the digits of 152 is 8. Given the starting and ending four digit numbers and a given target number such as 10, write a program to compute and print the number of instances where the sum of digits equals the target.
Write a static method called "evaluate" that takes a string as a parameter
In Java language  Write a static method called "evaluate" that takes a string as a parameter. The string will contain a postfix expression, consisting only of integer operands and the arithmetic operators +, -, *, and / (representing addition, subtraction, multiplication, and division respectively). All operations should be performed as integer operations. You may assume that the input string contains a properly-formed postfix expression. The method should return the integer that the expression evaluates to. The method MUST use a stack...
In an application write a method filterStack that takes a stack of integers as a parameter...
In an application write a method filterStack that takes a stack of integers as a parameter and filters its elements (in a new Stack) in a way that places the even elements at the bottom and the odd ones at the top. The original stack should remain unchanged. You should use a queue (only one queue) as a temporary storage. Use stack and queue operations only to solve this problem. No need to write the main method. For example, if...
use java for : 1. Write a method called indexOfMax that takes an array of integers...
use java for : 1. Write a method called indexOfMax that takes an array of integers and returns the index of the largest element. 2. The Sieve of Eratosthenes is “a simple, ancient algorithm for finding all prime numbers up to any given limit” (https://en.wikipedia. org/wiki/Sieve_of_Eratosthenes).Write a method called sieve that takes an integer parameter, n, and returns a boolean array that indicates, for each number from 0 to n -1, whether the number is prime.
Write a method that takes an integer array as its parameter and sorts the contents of...
Write a method that takes an integer array as its parameter and sorts the contents of the array in ascending order using the Insertion Sort algorithm. Call this method after the original array and other stats have been displayed. Once the array has been sorted by your method, display its contents to the screen in the same manner as the original array was displayed. CODE SO FAR: import java.util.*; public class ArrayInteger { public static void getRandomNumber(int A[],int n){ Random...
Java please. Write a static method sqrt()that takes a double argument and returns the square root...
Java please. Write a static method sqrt()that takes a double argument and returns the square root of that number using newton's method to compute result.
Write a java program calls the following methods: a. printStars(): Takes an int (n) as parameter...
Write a java program calls the following methods: a. printStars(): Takes an int (n) as parameter and prints n stars (*) using for loop. ex. 6 ******
.. Write a method called findNums that takes a two-dimension array of integers as a parameter...
.. Write a method called findNums that takes a two-dimension array of integers as a parameter and returns the number of times a two-digit number appears in the array. For example, if the array (as created by the program below) is 10 45 3 8 2 42 3 21 44 The value returned would be 5 (there are 5 two-digit numbers in the array) public class Question2 {    public static void main(String args[]){      int arr[][] = {{10, 45,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT