Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Java: Setup: create a new project add a class file called OddsEvens.java F

ID: 3665897 • Letter: U

Question

Using Java:

Setup: create a new project add a class file called OddsEvens.java

Features

Implement the following features:

(1 point) display a banner that features the name of the game : Let's play a game of odds and evens!

(1 point) allow the player to choose whether or not they'd like to play a cheating opponent

accept h or c in either uppercase or lowercase

note that the Scanner object allows you to get a string using .next()

however, if you want a character, you'll have take in a string and use .charAt(...)

either method is acceptable

Example output:What kind of player do you want the computer to be (h or c)? (H)onest Olivia (C)heating Chelsea

(1 point) allow the player to choose either odd or even by typing in 1 for odd or 2 for even

(3 points) if the player did not put in a 1 or a 2, the game ends immediately; display the message Oops - you have to choose odd (1) or even (2)!

(2 points) tell the player whether they chose odds or evens based on the number they entered: You chose odds or You chose evens

(1 point) display 1.. 2.. 3... Shoot! and ask the player for the number of fingers they reveal - 1 or 2

(3 points) if the player did not enter 1 or 2, the game ends immediately; display the message Oops - only 1 or 2 allowed!

(4 points) if the computer player is the cheater, always play the number that will give the computer the win:

Cheating computer cheats.

The computer puts out (winning number)

(3 points) otherwise, randomly choose 1 or 2 for the computer… for example: The computer puts out 2

(1 point) print out the total based on the player's input and the computer's random choice… for example, if the player chose 1, and the computer chose 2: The total is 3

(4 points) determine who won based on the total and whether or not the player chose odds or evens (see game rules above)… and display either You won! or You lost!

YOU CAN ASSUME THAT THE PLAYER WILL ALWAYS ENTER VALID INPUT WHEN ASKED FOR AN NUMBER

EXAMPLE:
Let's play a game of odds and evens! ====================================

What kind of player do you want the computer to be (h or c)? (H)onest Olivia (C)heating Chelsea

>c

Choose odd or even (type the number corresponding to your choice) 1 - Odd 2 - Even

>2

You chose evens 1.. 2.. 3... Shoot! (How many fingers - 1 or 2)

>2

Cheating computer cheats.

The computer puts out 1

The total is 3 You lost!

Explanation / Answer

ODDSEVENS.JAVA PROGRAM

Objective: create a game using simple java programming that allows a human player to play against the computer, or have the computer play against itself. The game is Odds or Evens where the human player enters a 1 or a 2 as their ‘hand’ and the computer’s number is generated by a Math.random function. To make things simple, I decided that the human will always ‘call’ Evens and the computer will always be Odds. Additions to the basic structure would be: have the loser pay the winner of the hand the sum of the throw, ie, if human entered a 2 and the computer threw a 1, the human loses and would pay the computer $3. If the computer threw a 2 as well, it would pay the human $4. Another addition would be to develop a strategy for the computer to play against the human where it threw a 1 or a 2 some x% of the time, and vary x to get different strategies.

Right now, my program compiles (just) and runs, but if I throw a 2 and always lose if I throw a 1, so I know that I have a bug where it’s only reading the user’s input and not adding the computer’s random number to get the total of the throw. I There are 3 classes, Game, Player, and Test -I know most of the issues are in the player class.

I know I have a lot of issues with it, but I’ve been looking at it and trying to get this going since yesterday morning, so some fresh eyes and comments would really help!Thanks!!


Player class:
public class Player

{

private boolean isHuman;

private String pName;

public int score;

// default constructor public

Player()

{

}

// initialising constructor public Player(boolean type, String aName)

{

this.isHuman = type; this.pName = aName; this.score = 0;

}

public void pChangeType(boolean pType) { isHuman = pType;

}

// change player type public void pChangeName(String aName) { pName = aName;

}

// change player name public boolean getStatus() { return isHuman;

}

// returns player type public String getName()

{

return pName;

}

// returns player name

}

Game class:
import java.util.*;

public class Game {

private Player playerOne;

private Player playerTwo;

private boolean gameType;

//true == player v comp, false = comp v comp

public Game(boolean gType)

{

this.gameType = gType;

if(gameType == true)

{

// begin a player v computer game playerOne = new Player(true, "Player1");

playerTwo = new Player(false, "Computer");

// proceed with the player v comp game this.

DoPlayerVComputerGame();

}

else

{

// begin a computer v computer game playerOne = new Player(false, "Computer1");

playerTwo = new Player(false, "Computer2");

this.DoComputerVComputerGame();

}

}

private void DoComputerVComputerGame()

{

// the computer v computer game function

} private void DoPlayerVComputerGame()

{

// the player v computer game int playerWishesToPlay = 1;

int pCurrent, cCurrent, value, cValue;

Scanner playerScan = new Scanner(System.in);

while (playerWishesToPlay == 1)

{

System.out.println("Enter 1 or 0");

pCurrent = playerScan.nextInt();

value = (int) Math.random() * 3;

playerOne.score = pCurrent + value; cCurrent = -1;

// set computer guess

// need to generate a random value cCurrent = (int)( Math.random() * 2);

if (cCurrent > 1) cCurrent = 1;

System.out.println("Computer Guess : " + cCurrent); cValue = (int)Math.random() * 3;

playerTwo.score = cCurrent + cValue;

// computers score if (playerOne.score %2 == 0) System.out.println("Player Wins"); else System.out.println("You Loose");

System.out.println("Continue play ? 1 == yes 2 == no ");

playerWishesToPlay = playerScan.nextInt();

}

}

}

Test class:
import java.util.*;

import java.math.*;

public class GamePlay {

private int iType;

private Game myGame;

private Scanner input = new Scanner(System.in);

public GamePlay() {

} private void beginPlay()

{

System.out.println("GAME OF TRUE OR FALSE ============================ "); System.out.println("Player vs Computer enter 0 Computer vs Computer enter 1 = ");

iType = input.nextInt();

if(iType == 0) myGame = new Game(true);

// player v comp else myGame = new Game(false); // comp v comp }

public static void main(String[] args)

{

GamePlay myGame = new GamePlay();

myGame.beginPlay();

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote