Question

In: Computer Science

The answer should be in JAVA. You will design and implement two classes to support a...

The answer should be in JAVA.

You will design and implement two classes to support a client program, RockPaperScissorsGame.java, to simulate Rock-Paper-Scissors game.

Read and understand the client program to find out the requirements for the HandShape and Player classes.

The rules of the Rock-Paper-Scissors game are:

    Scissors✌️ beats Paper✋ that beats Rock✊ that beats Scissors✌️

Additionally, to simplify the game logic (and complexify a little bit the HandSahpe class) , two players cannot show the same hand shape.

The followings are some sample runs:

$java RockPaperScissorsGame
Alice shows Paper
Bob shows Scissors
Bob wins!


$java RockPaperScissorsGame
Alice shows Paper
Bob shows Rock
Alice wins!


$java RockPaperScissorsGame
Alice shows Scissors
Bob shows Rock
Bob wins!

RockPaperScissorsGame.java

public class RockPaperScissorsGame {

        public static void main(String[] args) {
                
                String[] handShapeName = {"Rock", "Paper", "Scissors"};
                
                HandShape handShape = new HandShape();
                
                Player player1 = new Player("Alice");
                Player player2 = new Player("Bob");

                System.out.println(player1.getName() + " shows " + handShapeName[player1.showHand(handShape)]);
                System.out.println(player2.getName() + " shows " + handShapeName[player2.showHand(handShape)]);         
                
                System.out.println(player1.findWinner(player2) + "  wins!");
        }
}

Solutions

Expert Solution

public class RockPaperScissorsGame {

public static void main(String[] args) {
  
String[] handShapeName = {"Rock", "Paper", "Scissors"};
  
HandShape handShape = new HandShape();
  
Player player1 = new Player("Alice");
Player player2 = new Player("Bob");

System.out.println(player1.getName() + " shows " + handShapeName[player1.showHand(handShape)]);
System.out.println(player2.getName() + " shows " + handShapeName[player2.showHand(handShape)]);   
  
System.out.println(player1.findWinner(player2) + " wins!");
}
public class RockPaperScissor {


private Set<Situation> winSituations;


public RockPaperScissor() {

this.winSituations = new HashSet<>();

this.winSituations.add(new Situation("Rock", "Scissor"));
this.winSituations.add(new Situation("Scissor", "Paper"));
this.winSituations.add(new Situation("Paper", "Rock"));

}


public Result evaluateWinner(Situation situation) {

if (this.winSituations.contains(situation)) {
return Result.PLAYER1_WINS;
} else (this.winSituations.contains(situation.invert())) {
return Result.PLAYER2_WINS;
}

}

public static void main(String[] args) {

RockPaperScissor RockPaperScissor = new RockPaperScissor();

System.out.println(RockPaperScissor.evaluateWinner(new Situation("Rock", "Rock")));
System.out.println(RockPaperScissor.evaluateWinner(new Situation("Scissor", "Paper")));
System.out.println(RockPaperScissor.evaluateWinner(new Situation("Rock", "Paper")));

}

}


Related Solutions

The answer should be in JAVA. You will design and implement two classes to support a...
The answer should be in JAVA. You will design and implement two classes to support a client program, RockPaperScissorsGame.java, to simulate Rock-Paper-Scissors game. Read and understand the client program to find out the requirements for the HandShape and Player classes. The rules of the Rock-Paper-Scissors game are:     Scissors✌️ beats Paper✋ that beats Rock✊ that beats Scissors✌️ Additionally, to simplify the game logic (and complexify a little bit the HandSahpe class) , two players cannot show the same hand shape....
JAVA PROGRAM Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class...
JAVA PROGRAM Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class converts an infix expression to a postfix expression. The PostFixCalculator class evaluates a postfix expression. This means that the expressions will have already been converted into correct postfix form. Write a main method that prompts the user to enter an expression in the infix form, converts it into postfix, displays the postfix expression as well as it's evaluation. For simplicity, use only these operators,...
JAVA - Design and implement a class called Flight that represents an airline flight. It should...
JAVA - Design and implement a class called Flight that represents an airline flight. It should contain instance data that represent the airline name, the flight number, and the flight’s origin and destination cities. Define the Flight constructor to accept and initialize all instance data. Include getter and setter methods for all instance data. Include a toString method that returns a one-line description of the flight. Create a driver class called FlightTest, whose main method instantiates and updates several Flight...
This program focuses on programming with Java Collections classes. You will implement a module that finds...
This program focuses on programming with Java Collections classes. You will implement a module that finds a simplified Levenshtein distance between two words represented by strings. Your program will need support files LevenDistanceFinder.Java, dictionary.txt, while you will be implementing your code in the LevenDistanceFinder.java file. INSTRUCTIONS The Levenshtein distance, named for it's creator Vladimir Levenshtein, is a measure of the distance between two words. The edit distance between two strings is the minimum number of operations that are needed to...
Design and implement a class Rectangle to represent a rectangle. You should provide two Constructors for...
Design and implement a class Rectangle to represent a rectangle. You should provide two Constructors for the class, the first being the default constructor and the second which takes the basic dimensions and sets up the private member variables with the appropriate initial values. Methods should be provided that allow a user of the class to find out the length, width, area and perimeter of the shape plus a toString()method to print the values of the basic dimensions. Now implement...
Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class converts an...
Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class converts an infix expression to a postfix expression. The PostFixCalculator class evaluates a postfix expression. This means that the expressions will have already been converted into correct postfix form. Write a main method that prompts the user to enter an expression in the infix form, converts it into postfix, displays the postfix expression as well as it's evaluation. For simplicity, use only these operators, + ,...
JAVA Specify, design, and implement a class called PayCalculator. The class should have at least the...
JAVA Specify, design, and implement a class called PayCalculator. The class should have at least the following instance variables: employee’s name reportID: this should be unique. The first reportID must have a value of 1000 and for each new reportID you should increment by 10. hourly wage Include a suitable collection of constructors, mutator methods, accessor methods, and toString method. Also, add methods to perform the following tasks: Compute yearly salary - both the gross pay and net pay Increase...
(Code in Java please) You need to implement the GarageDoor, GarageDoorUpCommand and GarageDoorDownCommand classes (similar to...
(Code in Java please) You need to implement the GarageDoor, GarageDoorUpCommand and GarageDoorDownCommand classes (similar to Light, LightOnCommand and LightOffCommand), AND (edited) Implement the CeilingFan class (with state, see p. 220), AND CeilingFanHighCommand (p. 221), CeilingFanMediumCommand, CeilingFanLowCommand, CeilingFanOffCommand (WITH Undo), AND TEST your CeilingFan classes (see pp. 222 and 223), AND Finally, implement and Test the MacroCommand class on pp. 224-227 EXAMPLE output for homework assignment…………… ======= The COMMAND PATTERN ============= guest house garage door is UP guest house garage...
Java - Design and implement an application that creates a histogram that allows you to visually...
Java - Design and implement an application that creates a histogram that allows you to visually inspect the frequency distribution of a set of values. The program should read in an arbitrary number of integers that are in the range 1 to 100 inclusive; then produce a chart similar to the one below that indicates how many input values fell in the range 1 to 10, 11 to 20, and so on. Print one asterisk for each value entered. Sample...
java 8.3: Histogram Design and implement an application that creates a histogram that allows you to...
java 8.3: Histogram Design and implement an application that creates a histogram that allows you to visually inspect the frequency distribution of a set of values. The program should read in an arbitrary number of integers that are in the range 1 to 100 inclusive; then produce a chart similar to the one below that indicates how many input values fell in the range 1 to 10, 11 to 20, and so on. Print one asterisk for each value entered....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT