Paper Scissors Rock “Strategy” Purpose:To review class inheritance. Directions and Examples: Download the starter code from the dropbox where you got this assignment. This code contains a class  called Player that randomly chooses paper, scissors or rock with equal probability. It also contains a class  called PaperScissorsRock that creates two Player objects, has them play one million games, and counts  the number of times Player 1 wins.  Your task for the practice lab is to create a subclass of Player called StrategicPlayer. The StrategicPlayer  class should have the following fields and methods: private double percentPaper – the likelihood (between 0 and 1) that the player will choose paper private double percentScissors – the likelihood (between 0 and 1) that the player will choose scissors private double percentRock – the likelihood (between 0 and 1) that the player will choose rock public StrategicPlayer(double paper, double scissors, double rock) – a constructor that initializes the  object’s fields The class should also override the go method from the Player superclass to choose paper, scissors or  rock in the desired percentages. Modify the driver program so that Player 1 is a StrategicPlayer instead of a regular Player and re-run the  program. Hint: the outcome should be little changed from the original version no matter what  percentages you use, because there is no strategy in Paper Scissors Rock

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Paper Scissors Rock “Strategy”


Purpose:To review class inheritance.


Directions and Examples:
Download the starter code from the dropbox where you got this assignment. This code contains a class 
called Player that randomly chooses paper, scissors or rock with equal probability. It also contains a class 
called PaperScissorsRock that creates two Player objects, has them play one million games, and counts 
the number of times Player 1 wins. 


Your task for the practice lab is to create a subclass of Player called StrategicPlayer. The StrategicPlayer 
class should have the following fields and methods:
private double percentPaper – the likelihood (between 0 and 1) that the player will choose paper
private double percentScissors – the likelihood (between 0 and 1) that the player will choose scissors
private double percentRock – the likelihood (between 0 and 1) that the player will choose rock
public StrategicPlayer(double paper, double scissors, double rock) – a constructor that initializes the 
object’s fields
The class should also override the go method from the Player superclass to choose paper, scissors or 
rock in the desired percentages.
Modify the driver program so that Player 1 is a StrategicPlayer instead of a regular Player and re-run the 
program. Hint: the outcome should be little changed from the original version no matter what 
percentages you use, because there is no strategy in Paper Scissors Rock 

Given Code:

public class PaperScissorsRock {
   
    Player player1;
    Player player2;
   
   
    public PaperScissorsRock(Player player1, Player player2) {
        this.player1 = player1;
        this.player2 = player2;
    }
   
   
    public static String whoWon(String player1Move, String player2Move) {
       
        if (player1Move.equals(player2Move)) {
            return "Tie";
           
        } else {
           
            if (player1Move.equals("Rock")) {
                if (player2Move.equals("Scissors")) {
                    return "Player 1";
                } else {
                    return "Player 2";
                }
               
            } else if (player1Move.equals("Scissors")) {
                if (player2Move.equals("Rock")) {
                    return "Player 2";
                } else {
                    return "Player 1";
                }
               
            } else {
                if (player2Move.equals("Rock")) {
                    return "Player 1";
                } else {
                    return "Player 2";
                }
            }
        }
    }
   

    public static void main(String[] args) {

        Player player1 = new Player();
        Player player2 = new Player();
       
        int player1Wins = 0;
       
        for (int i=0; i<1000000; i++) {
            String player1Move = player1.go();
            String player2Move = player2.go();
           
            String winner = whoWon(player1Move, player2Move);
           
            if (winner.equals("Player 1")) {
                player1Wins++;
            }
        }

        System.out.println("Player 1 won " + player1Wins + " times");
    }
}

public class Player {

    public String go() {
       
        double random = Math.random();
       
        if (random < .33) {
            return "Paper";
        } else if (random < .66) {
            return "Scissors";
        } else {
            return "Rock";
        }
    }
}

public class Player {

    public String go() {
       
        double random = Math.random();
       
        if (random < .33) {
            return "Paper";
        } else if (random < .66) {
            return "Scissors";
        } else {
            return "Rock";
        }
    }
}
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY