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

write a Java class to play a variant of Rock-Paper-Scissors called Hunter-Bear-N

ID: 3746439 • Letter: W

Question

write a Java class to play a variant of Rock-Paper-Scissors called Hunter-Bear-Ninja against the computer. This game works similarly to Rock-Paper-Scissors but with the rules of:

1) Hunter shoots bear

2) Bear eats ninja

3) Ninja kills the hunter

Multiple games should be able to be played. The game should prompt the user after each game if they would like to play again (Asking for Yy or Nn). Each iteration of the game, it should tell them what their win/loss ratio is.

In addition, implement an "intelligent strategy" for your computer player. This does not have to be particularly smart, but implement some method to try and "outfox" the human player.

Explanation / Answer

import java.util.Scanner;

import java.util.Random;

class Main

{

public static void main(String[] args) //main functiom

{

Random randnum;

randnum = new Random(); //random

Scanner sc=new Scanner(System.in);

int ch,n; //variable declaration

String us;

String c;

System.out.println("**** Welcome Hunter-Bear-Ninja Game*****");

do{

System.out.println("The Rules are ");

System.out.println("1. Hunter shoots bear");

System.out.println("2. Bear eats ninja");

System.out.println("3. Ninja kills the hunter");

System.out.println("Choose difficulty");

System.out.println("1.Easy");

System.out.println("2.Hard");

//acepting choice from the user

System.out.println("Enter your choice");

ch=sc.nextInt();

String arr[]={"Hunter","Bear","Ninja"};

n = randnum.nextInt(2) + 0; //generating random number

if(ch==1)

{

System.out.println("Enter your choice(Hunter/Bear/Ninja)");

us=sc.next();

if(us.equalsIgnoreCase("Hunter") && arr[n].equalsIgnoreCase("Hunter"))

System.out.println("Draw");

if(us.equalsIgnoreCase("Hunter") && arr[n].equalsIgnoreCase("Bear"))

{

System.out.println("Hunter shoots bear");

System.out.println("Player is the winner");

}

if(us.equalsIgnoreCase("Hunter") && arr[n].equalsIgnoreCase("Ninja"))

{

System.out.println("Ninja kills the hunter");

System.out.println("Computer is the winner");

}

if(us.equalsIgnoreCase("Bear") && arr[n].equalsIgnoreCase("Bear"))

System.out.println("Draw");

if(us.equalsIgnoreCase("Bear") && arr[n].equalsIgnoreCase("Ninja"))

{

System.out.println("Bear eats ninja");

System.out.println("Player is the winner");

}

if(us.equalsIgnoreCase("Bear") && arr[n].equalsIgnoreCase("Hunter"))

{

System.out.println("Hunter shoots bear");

System.out.println("Computer is the winner");

}

if(us.equalsIgnoreCase("Ninja") && arr[n].equalsIgnoreCase("Ninja"))

System.out.println("Draw");

if(us.equalsIgnoreCase("Ninja") && arr[n].equalsIgnoreCase("Hunter"))

{

System.out.println("Ninja Kills the hunter");

System.out.println("Player is the winner");

}

if(us.equalsIgnoreCase("Ninja") && arr[n].equalsIgnoreCase("Bear"))

{

System.out.println("Bear eats ninja");

System.out.println("Computer is the winner");

}

}

if(ch==2)

{

System.out.println("Enter your choice(Hunter/Bear/Ninja)");

us=sc.next();

if(us.equalsIgnoreCase("Ninja"))

{

System.out.println("Bear eats ninja");

System.out.println("Computer is the winner");

}

if(us.equalsIgnoreCase("Hunter"))

{

System.out.println("Ninja kills the hunter");

System.out.println("Computer is the winner");

}

if(us.equalsIgnoreCase("Bear"))

{

System.out.println("Hunter shoots bear");

System.out.println("Computer is the winner");

}

}

//asking for playing again

System.out.println("Do you want to play again(Y/N)");

c=sc.next();

}while(!c.equalsIgnoreCase("N"));

}

}