Question

In: Computer Science

import java.io.*; import java.util.*; /** * * * * * Lab Project 9: Rock, Paper, Scissors...

import java.io.*;
import java.util.*;

/**
 *
 *
 * 
 * 
 * Lab Project 9: Rock, Paper, Scissors
 *
 * @authors *** Replace with your names here ***
 */
public class lab
{
  // global named constant for random number generator
  static Random gen = new Random();
  
  // global named constants for game choices
  static final int ROCK = 1;
  static final int PAPER = 2;
  static final int SCISSORS = 3;
  
  // global names constants for game outcomes
  static final int PLAYER1_WINS = 11;
  static final int PLAYER2_WINS = 12;
  static final int DRAW = 3;
  
  // global named constant for error condition
  static final int ERROR = -1;
  
  /**
   * 1. Get human player's choice
   * 2. Get computer player's (random) choice
   * 3. Check human player's choice
   * 4. Check computer player's choice
   * 5. Announce winner
   */
  public static void main(String[] args)
  {
    Scanner scan = new Scanner(System.in);
    PrintStream output = System.out;
    
    int player1, player2;
    
    // get player 1 input as 1 (rock), 2 (paper or 3 (scissors)
    output.print("Choose 1 (rock), 2 (paper), or 3 (scissors): ");
    player1 = scan.nextInt();
    
    /* Lab 9.1
     *
     * *** Add code here to validate that player1 has entered
     *     an integer between 1 and 3
     *     otherwise, ABORT the program
     */
    
    
    // echo human player's choice
    System.out.print(" You chose ");
    if (player1 == ROCK) { System.out.println("rock"); }
    else if (player1 == PAPER) { System.out.println("paper"); }
    else { System.out.println("scissors"); }
    
    // now computer picks one randomly
    
    output.println("Now I choose one ...");
    
    /*
     Lab 9.2
     
     *** Add code to and un-comment the following line so that
     player2 is set to a random integer between 1 and 3,
     using the gen Random object, ALREADY DECLARED AS
     A GLOBAL VARIABLE:
     */
    
    // player2 = ...;
    
    System.out.print(" I choose ");
    
    /* Lab 9.3
     *
     * *** Add code here to output the computer's choice
     *     as "rock", "paper" or "scissors"
     */
    
    
    
    /* Lab 9.4
     *
     * *** Add code below to compare player input against
     *     computer's choice and output results:
     *
     *     if human player chose ROCK:
     *       call rockChoice method with computer choice
     *       output the game's outcome (returned from rockChoice)
     *     otherwise, if human player chose PAPER:
     *       call paperChoice method with computer choice
     *       output the game's outcome (returned from paperChoice)
     *    otherwise, if human player chose SCISSORS:
     *       call scissorcChoice method with computer choice
     *       output the game's outcome (returned from scissorcChoice)
     */
    
    
  } // end main
  
  
  /**
   * Lab 9.5
   * 
   * rockChoice(int) -> int
   * 
   * method consumes the computer player's choice (ROCK, PAPER or SCISSORS),
   *   assuming the human player has chosen ROCK
   * method produces game outcome (PLAYER1_WINS, PLAYER2_WINS, or DRAW)
   * 
   * ex1: rockChoice(ROCK) -> DRAW
   * ex2: rockChoice(PAPER) -> PLAYER2_WINS
   * ex3: rockChoice(SCISSORS) -> PLAYER1_WINS
   * ex4: rockChoice(0) -> ERROR
   * ex5: rockChoice(-1) -> ERROR
   * ex6: rockChoice(4) -> ERROR
   * 
   * *** ADD METHOD CODE HERE ***
   */
  
  
  /**
   * Lab 9.6
   * 
   * paperChoice(int) -> int
   * 
   * method consumes the computer player's choice (ROCK, PAPER or SCISSORS),
   *   assuming the human player has chosen PAPER
   * method produces game outcome (PLAYER1_WINS, PLAYER2_WINS, or DRAW)
   * 
   * ex1: paperChoice(ROCK) -> PLAYER1_WINS
   * ex2: paperChoice(PAPER) -> DRAW
   * ex3: paperChoice(SCISSORS) -> PLAYER2_WINS
   * ex4: paperChoice(0) -> ERROR
   * ex5: paperChoice(-1) -> ERROR
   * ex6: paperChoice(4) -> ERROR
   * 
   * *** ADD METHOD CODE HERE ***
   */
  
  
  /**
   * Lab 9.7
   * 
   * scissorsChoice(int) -> int
   * 
   * method consumes the computer player's choice (ROCK, PAPER or SCISSORS),
   *   assuming the human player has chosen SCISSORS
   * method produces game outcome (PLAYER1_WINS, PLAYER2_WINS, or DRAW)
   * 
   * ex1: scissorsChoice(ROCK) -> PLAYER2_WINS
   * ex2: scissorsChoice(PAPER) -> PLAYER1_WINS
   * ex3: scissorsChoice(SCISSORS) -> DRAW
   * ex4: scissorsChoice(0) -> ERROR
   * ex5: scissorsChoice(-1) -> ERROR
   * ex6: scissorsChoice(4) -> ERROR
   * 
   * *** ADD METHOD CODE HERE ***
   */
  
  
} // end class lab

Solutions

Expert Solution


Related Solutions

I'm getting an error for this code? it won't compile import java.util.*; import java.io.*; public class...
I'm getting an error for this code? it won't compile import java.util.*; import java.io.*; public class Qup3 implements xxxxxlist {// implements interface    // xxxxxlnk class variables    // head is a pointer to beginning of rlinked list    private node head;    // no. of elements in the list    // private int count; // xxxxxlnk class constructor    Qup3() {        head = null;        count = 0;    } // end Dersop3 class constructor   ...
Please convert this java program to a program with methods please. import java.io.*; import java.util.*; public...
Please convert this java program to a program with methods please. import java.io.*; import java.util.*; public class Number{ public static void main(String[] args) {    Scanner scan = new Scanner(System.in); System.out.println("Enter 20 integers ranging from -999 to 999 : "); //print statement int[] array = new int[20]; //array of size 20 for(int i=0;i<20;i++){ array[i] = scan.nextInt(); //user input if(array[i]<-999 || array[i]>999){ //check if value is inside the range System.out.println("Please enter a number between -999 to 999"); i--; } } //...
Convert this java code from hashmap into arraylist. import java.io.*; import java.util.*; public class Solution {...
Convert this java code from hashmap into arraylist. import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); HashMap labs = new HashMap(); while (true) { System.out.println("Choose operation : "); System.out.println("1. Create a Lab"); System.out.println("2. Modify a Lab"); System.out.println("3. Delete a Lab"); System.out.println("4. Assign a pc to a Lab"); System.out.println("5. Remove a pc from a Lab"); System.out.println("6. Quit"); int choice = sc.nextInt(); String name=sc.nextLine(); switch (choice) { case 1:...
write a python script for rock scissors paper game
write a python script for rock scissors paper game
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper,...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows: • Rock beats scissors, because a rock can break a pair of scissors. • Scissors beats paper, because scissors can cut paper. • Paper beats rock, because a piece of paper can cover a rock. Create a game...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper,...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows: • Rock beats scissors, because a rock can break a pair of scissors. • Scissors beats paper, because scissors can cut paper. • Paper beats rock, because a piece of paper can cover a rock. Create a game...
Write a Java class that determines the winner of a rock, paper scissors game. Assume the...
Write a Java class that determines the winner of a rock, paper scissors game. Assume the input from the user is always valid (so no need to check), that is it contains either one of `R`, `P`, or `S` as a single character, or has matching parenthesis, like, `(S&P)` or `((R&P)&S)`, and the `&` character. So for example, the user inputs `(P&R)` and the program will output `P` since paper beats rock. Or if the user inputs `((S&R)&(S&S))` the output...
Solve the scissors, paper, rock game. This game is well known in many parts of the...
Solve the scissors, paper, rock game. This game is well known in many parts of the world. Two players simultaneously present a hand in one of three positions: an open hand (paper), a closed fist (rock), or two open fingers (scissors). The payoff is 1 unit according to the rule “Paper covers rock, rock breaks scissors, and scissors cut paper.” If both players present the same form, the payoff is 0. Set up the payoff matrix for the game and...
One file java program that will simulate a game of Rock, Paper, Scissors. One of the...
One file java program that will simulate a game of Rock, Paper, Scissors. One of the two players will be the computer. The program will start by asking how many winning rounds are needed to win the game. Each round will consist of you asking the user to pick between rock, paper, and scissors. Internally you will get the computers choice by using a random number generator. Rock beats Scissors, Paper beats Rock, and Scissors beats Paper. You will report...
Please write a scheme code for the rock paper scissors game between a player and the...
Please write a scheme code for the rock paper scissors game between a player and the computer (AI). In scheme programming language please.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT