Question
Please help with Java Programming project!
Project outcomes: Develop a Java program that: .reads input from the keyboard using a Scanner object and its methods uses iteration (while, do while, or for statements uses String comparison methods. follows standard acceptable programming practices. .handles integer overflow errors Prep Readings: Absolute Java Chapter 1 3 and Security Injection Labs (Integer Error) Project Requirements: Write a Java program that plays a mathematical game called Taking Stones which is based on the Chinese game of Tsyan-shiz. In this game, the person who runs your program will be the human player and your program will be a simple Artificial Intelligence (Al that will serve as the other player, as well as provide the narrative for the game and keep score. Your program must keep score impartially while participating in the game, but this is not a difficult task for the computer. 2. The rules of the game are: a The human player and the computer will role a (virtual) pair of dice at the beginning of each game to see who goes first. b. The player who goes first provides the number of stones that will be in the pile. The number must be between 10 and 50 Each player then removes some number (between 1 and 3) of stones from the pile until one player removes the final stone. The player who goes first
media%2F3ab%2F3ab43194-8153-4874-a71d-05
media%2F719%2F7191c9a3-aa8a-44c2-9d75-c1
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Random;
import java.util.Scanner;

public class HelloWorld{

public static void main(String []args){
int human, computer,dice1,dice2,c=0,h=0;
String name;
Random r = new Random();
Scanner sc=new Scanner(System.in);
dice1=r.nextInt(50);
dice2=r.nextInt(50);
System.out.println("Your name: ");
name=sc.next();
System.out.println("Welcome "+name+" to the game of Taking Stone");
if(dice1>dice2)
{
System.out.println("Dice is won by human");
System.out.println("Provided number of stones: ");
human=sc.nextInt();
computer=r.nextInt((50 - 10) + 1) + 10;
System.out.println("Number of stones provided by computer: "+computer);
while(h!=3 || c!=3)
{
while(true)
{
System.out.println("Choose number (1-3) to remove first set of number from piles: ");
int num1=sc.nextInt();
if(num1>3 || num1<0)
{
System.out.println("Number is invalid");
System.out.println("please choose number between 1 to 3!!!");
}
else
{
h++;
break;
}
}
int num2=r.nextInt((3 - 1) + 1) + 3;
c++;
}
  
}
else
{
System.out.println("Dice is won by computer");
computer=r.nextInt((50 - 10) + 1) + 10;
System.out.println("Number of stones provided by computer: "+computer);
System.out.println("Provided number of stones: ");
human=sc.nextInt();
while(h!=3 || c!=3)
{
int num2=r.nextInt((3 - 1) + 1) + 3;
c++;
while(true)
{
System.out.println("Choose number (1-3) to remove first set of number from piles: ");
int num1=sc.nextInt();
if(num1>3 || num1<0)
{
System.out.println("Number is invalid");
System.out.println("please choose number between 1 to 3!!!");
}
else
{
h++;
break;
}
}
}
}
if(h>c)
System.out.println("Congrats!!!! Human won");
else System.out.println("Congrats!!!! Computer won");
}
}

Your name: Sarika Welcome Sarika to the game of Taking Stone Dice is won by human Provided number of stones: 34 Number of sto

Add a comment
Know the answer?
Add Answer to:
Please help with Java Programming project! Project outcomes: Develop a Java program that: .reads input from...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Programming Project #5 Project Outcomes: Develop a Java program that Uses selection constructs (if, and if...

    Programming Project #5 Project Outcomes: Develop a Java program that Uses selection constructs (if, and if else). Uses the Java iteration constructs (while, do, for). Uses static variables. Ensure integer variables input are within a range that will not cause integer overflow. Uses proper design techniques including reading UML Class Diagrams Background Information: The Unified Modeling Language (UML) provides a useful notation for designing and developing object-oriented software systems. One of the basic components of the UML is a class...

  • Using very basic Java programming Write a program that lets the user play the game of...

    Using very basic Java programming Write a program that lets the user play the game of Rock, Paper, Scissors against the computer.The program should use an array of Strings with the names of the choices.The program should loop until the human player decides to quit.The game should keep track of how many times the human won, lost, or tied and present those values when the game ends.

  • I need to create a Tic Tac Toe program in C++. These are the requirements Write...

    I need to create a Tic Tac Toe program in C++. These are the requirements Write a program that allows the computer to play TicTacToe against a human player or allow two human players to play one another. Implement the following conditions: The player that wins the current game goes first in the next round, and their symbol is X. The other player will be O. Keep track of the number of games played, wins, and draws for each player....

  • You will write a two-class Java program that implements the Game of 21. This is a...

    You will write a two-class Java program that implements the Game of 21. This is a fairly simple game where a player plays against a “dealer”. The player will receive two and optionally three numbers. Each number is randomly generated in the range 1 to 11 inclusive (in notation: [1,11]). The player’s score is the sum of these numbers. The dealer will receive two random numbers, also in [1,11]. The player wins if its score is greater than the dealer’s...

  • Need Help with homework problem writing the game of nim in Python IDLE. Its a well...

    Need Help with homework problem writing the game of nim in Python IDLE. Its a well known game with a number of variants. The following variant has an interesting winning strategy. Two players alternately take marbles from a pile. In each move, a player chooses how many marbles to take. The player must take at least one but at most half of the marbles. Then the other player takes a turn. The player who takes the last marble loses. Instructions...

  • For your final project you will incorporate all your knowledge of Java that you learned in this class by programming the game of PIG. The game of Pig is a very simple jeopardy dice game in which two p...

    For your final project you will incorporate all your knowledge of Java that you learned in this class by programming the game of PIG. The game of Pig is a very simple jeopardy dice game in which two players race to reach 100 points. Each turn, a player repeatedly rolls a die until either a 1 is rolled or the player holds and scores the sum of the rolls (i.e. the turn total). At any time during a player's turn,...

  • Programming Project 3 See Dropbox for due date Project Outcomes: Develop a Java program that uses:...

    Programming Project 3 See Dropbox for due date Project Outcomes: Develop a Java program that uses: Exception handling File Processing(text) Regular Expressions Prep Readings: Absolute Java, chapters 1 - 9 and Regular Expression in Java Project Overview: Create a Java program that allows a user to pick a cell phone and cell phone package and shows the cost. Inthis program the design is left up to the programmer however good object oriented design is required.    Project Requirements Develop a text...

  • Java CSC252   Programming II    Static Methods, Enums, Constants, Random Rock Paper Scissors Write a program that...

    Java CSC252   Programming II    Static Methods, Enums, Constants, Random Rock Paper Scissors Write a program that allows the user to play "Rock, Paper, Scissors". Write the RPS class. All code should be in one file. main() will be part of the RPS class, fairly small, and contain only a loop that asks the user if they want to play "Rock, Paper, Scissors". If they say yes, it calls the static method play() of the RPS class. If not, the program...

  • In this programming project you are required to develop a 16-bit CRC program using Java and...

    In this programming project you are required to develop a 16-bit CRC program using Java and test your program with the crctest.txt file. The corresponding 16-bit CRC should be attached to the end of each line. You are asked to use a 16-bit polynomial - x^16+x^12+x^5+1. You are allowed to use the Java 16-bit CRC library - java.io* & java.util.zip.CRC, but your max points will be 20/25. The contents inside the crctest.txt file include: Computer Science! Fall Foliage around Poconos...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT