Question: 1.Following the instructions in Class Notes How Tos How to import Java source code (.java) files into a NetBeans project on this Isidore site: i.create

1.Following the instructions in Class Notes How Tos How to import Java source code (.java) files into a NetBeans project on this Isidore site:

i.create a new empty NetBeans project named CPS150_Lab14

ii.delete the auto-generated main class (CPS150_Lab14.java)

iii.download/import the replacement CPS150_Lab14.java source code into the project

2.Open the source code and:

i.Add your name to the comment block immediately above public class CPS150_Lab14(indicated by *** Replace with your name ***)

ii.Add the code as described by (and immediately below) each of the comment blocks labeled Lab 14.1 - 14.7.

/*

* CPS150_Lab14.java

*/

package cps150_lab14;

import java.io.*;

import java.util.*;

/**

* CPS 150, Spring 2017 semester

*

* Section: 03

*

* Lab Project 14: Rock, Paper, Scissors

*

* @author

*/

public class CPS150_Lab14

{

// global named constant for random number generator

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 14.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 14.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 14.3

//

// *** Add code here to output the computer's choice

// as "rock", "paper" or "scissors"

// Lab 14.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 14.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 14.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 14.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 CPS150_Lab14

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!