Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The purpose of this assignment is to assess your understanding of conditional and iterative operations, string comparison, and input validation by creating a game that

The purpose of this assignment is to assess your understanding of conditional and iterative operations, string comparison, and input validation by creating a game that is a little twist on the classic rock-paper-scissors game called Gorilla-Terminator-Gangster-Warrior-Zombie (AKA Moropinzee). I'm working on the code myself and I am able to get the conditions for "Nobody wins" & if player1 enter 1 and player2 enters 2, but the rest of my conditions will not print out my string. For example if I put player1 enters 4 & player2 enters 3 the winner will not print out. What am i missing or doing wrong ? I have added "invalid user input" if the user enters a number that is not 1 -5. I also need help with asking if they would like to play again. The response given here must be a String, even if the value is "YES", "no", "Yes", "n" or "Y". If they answer "yes", or any variation therein, the game repeats and quits otherwise.

import java.util.Scanner;

public class Assignment2 { public static void main(String[] args) { String personPlay1 = "Player 1"; String personPlay2 = "Player 2"; int Gorilla = 1; int Terminator = 2; int Gangster = 3; int Warrior = 4; int Zombie = 5;

String response;

Scanner scan = new Scanner(System.in);

System.out.println("Hey, let's play Moropinzee! " + "Please enter a move. ");

System.out.println("Player 1, Enter a number 1-5 for Gorilla, Terminator, Gangster, Warrior or Zombie:"); personPlay1 = scan.next();

System.out.println("Player 2, Enter a number 1-5 for Gorilla, Terminator, Gangster, Warrior or Zombie:"); personPlay2 = scan.next();

if (personPlay1.equals(personPlay2)) { System.out.println("Nobody wins!"); } else if (personPlay1.equals("1")) { if (personPlay2.equals("2")) { System.out.println("Gorilla unplugs Terminator. Player 2 wins!!"); } else if (personPlay2.equals("5")) { System.out.println("Zombie savages Gorilla. Player 2 wins!!"); } else if (personPlay2.equals("3")) { System.out.println("Gangster skewers Gorilla. Player 1 wins!!"); } else if (personPlay2.equals("4")) { System.out.println("Warrior decapitates Terminator. Player 2 wins!!"); } else if (personPlay1.equals("2")) { if (personPlay2.equals("1")) { System.out.println("Gorilla unplugs Terminator. Player 1 wins!!"); } else if (personPlay2.equals("3")) { System.out.println("Gangster unplugs Terminator. Player 2 wins!!"); } else if (personPlay2.equals("4")) { System.out.println("Warrior decapitates Terminator. Player 2 wins!!"); } else if (personPlay2.equals("5")) { System.out.println("Terminator crushes Zombie. Player 1 wins!!"); } } else if (personPlay1.equals("3")) { if (personPlay2.equals("2")) { System.out.println("Gangster unplugs Terminator. Player 1 wins!!"); } else if (personPlay2.equals("4")) { System.out.println("Warrior chops Gangster. Player 1 wins!!"); } else if (personPlay2.equals("5")) { System.out.println("Zombie eats Gangster. Player 2 wins!!"); } else if (personPlay2.equals("1")) { System.out.println("Gangster skewers Gorilla. Player 1 wins!!"); } } else if (personPlay1.equals("4")) { if (personPlay2.equals("2")) { System.out.println("Warrior decapitates Terminator. Player 1 wins!!"); } else if (personPlay2.equals("3")) { System.out.println("Warrior chops Gangster. Player 2 wins!!"); } else if (personPlay2.equals("5")) { System.out.println("Warrior decapitates Zombie. Player 2 wins!!"); } else if (personPlay2.equals("1")) { System.out.println("Gorilla fools Warrior. Player 2 wins!!"); } } else if (personPlay1.equals("5")) { if (personPlay2.equals("2")) { System.out.println("Terminator crushes Zombie. Player 2 wins!!"); } else if (personPlay2.equals("3")) { System.out.println("Zombie eats Gangster. Player 1 wins!!"); } else if (personPlay2.equals("4")) { System.out.println("Warrior decapitates Zombie. Player 1 wins!!"); } else if (personPlay2.equals("1")) { System.out.println("Zombie savages Gorilla. Player 2 wins!!"); } else System.out.println("Invalid user input."); } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions