Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In the game that you created below, enter the name of the player and add it to a file. The program should be able to

In the game that you created below, enter the name of the player and add it to a file. The program should be able to read the file and pull a list of all the users who have played with the computer. import java.io.*; import java.util.Scanner; public class MatchStickGame { private int mSticks; private int choice; public void playComputer(Scanner sc) { switch (choice) { case 1: choice = 4; break; case 2: choice = 3; break; case 3: choice = 2; break; case 4: choice = 1; break; } mSticks -= choice; System.out.println("Computer picked:" + choice); System.out.println("No. of matchsticks remaining:" + mSticks); playHuman(sc); } public void playHuman(Scanner sc) { System.out.print("Your turn->Pick the matchsticks:"); choice = sc.nextInt(); if (choice > 4) { System.out.println("You can pick 1,2 3 or 4 sticks"); playHuman(sc); } if ((mSticks - choice) == 0) { System.out.println("You lose"); return; } mSticks -= choice; System.out.println("No. of matchsticks remaining:" + mSticks); playComputer(sc); } public static void main(String args[]) { MatchStickGame m = new MatchStickGame(); Scanner sc=new Scanner(System.in); System.out.println("You can pick 1,2 3 or 4 sticks"); System.out.println("Number of matchsticks to be used:"); m.mSticks = sc.nextInt(); int turn = (m.mSticks % 5) - 1; if (turn > 0) { m.mSticks -= turn; System.out.println("Computer picked:" + turn); System.out.println("No. of matchsticks remaining:" + m.mSticks); m.playHuman(sc); } else { m.playHuman(sc); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The World Wide Web And Databases International Workshop Webdb 98 Valencia Spain March 27 28 1998 Selected Papers Lncs 1590

Authors: Paolo Atzeni ,Alberto Mendelzon ,Giansalvatore Mecca

1st Edition

3540658904, 978-3540658900

More Books

Students also viewed these Databases questions

Question

(c) Can you fit the original model using this type of analysis?

Answered: 1 week ago

Question

Design a job advertisement.

Answered: 1 week ago