SlideShare uma empresa Scribd logo
1 de 2
Description In a game of Tic Tac Toe, two players take turns making an available cell in a 3 x 3
grid with their respective tokens (either X or O). When one player has placed three tokens in a
horizontal, vertical, or diagonal row on the grid, the game is over and that player has won. A
stalemate occurs when all the cells on the grid have been filled with tokens and neither player
has achieved a win. Write a program that emulates a Tic Tac Toe game. When you are done, a
typical session will look like this: Welcome to tic-tac-toe. Enter coordinates for your move
following the X and O prompts. 1 2 3 A | | ----- B | | ----- C | | X:A2 1 2 3 A |X| ----- B | | ----- C | |
O:B3 1 2 3 A |X| ----- B | |O ----- C | | And so on. Illegal moves will prompt the user again for a
new move. A win or a stalemate will be announced, mentioning the winning side if any. The
program will terminate whenever a single game is complete. For this lab, you will be provided
with a base file to work with. The base file can be downloaded from:
https://github.com/victoryu/CIS35A-LabsLinks to an external site. You will add and/or modify
the code, as instructed below. Do not change the overall structure of the program. Just fill in with
your code at TODO and Step #. This file has the general framework of the TicTacToe class. An
object of this class will represent a tic-tac-toe "board". The board will be represented internally
by a two dimensional array of characters (3 x 3), and by a character indicating who's turn it is
('X' or 'O'). These are stored in the class instance variables as follows. private char[][] board;
private char player; // 'X' or 'O' You will need to define the following methods: 1. A constructor:
public TicTacToe() to create an empty board, with initial value of a space (' ') 2. play method
public boolean play(String position) if position represents a valid move (e.g., A1, B3), add the
current player's symbol to the board and return true. Otherwise, return false. 3. switchTurn
method public void switchTurn() switches the current player from X to O, or vice versa. 4. won
method public boolean won() Returns true if the current player has filled three in a row, column
or either diagonal. Otherwise, return false. 5. stalemate method public boolean stalemate()
Returns true if there are no places left to move; 6. printBoard method public void print() prints
the current board 7. Use the following test code in your main method to create a TicTacToe
object and print it using the printBoard method given, so as to test your code. Your printBoard
method should produce the first board in the example above. public static void main(String[]
args) { Scanner in = new Scanner(System.in); TicTacToe game = new TicTacToe();
System.out.println("Welcome to Tic-tac-toe"); System.out.println("Enter coordinates for your
move following the X and O prompts"); while(!game.stalemate()) { game.print();
System.out.print(game.getPlayer() + ":"); //Loop while the method play does not return true
when given their move. //Body of loop should ask for a different move
while(!game.play(in.next())) { System.out.println("Illegal move. Enter your move.");
System.out.print(game.getPlayer() + ":"); } //If the game is won, call break; if(game.won())
break; //Switch the turn game.switchTurn(); } game.print(); if(game.won()) {
System.out.println("Player "+game.getPlayer()+" Wins!!!!"); } else {
System.out.println("Stalemate"); } } Test the following cases: 1. A player makes a legal
movement; 2. A player makes an illegal movement; 3. Player X wins 4. Player X loses 5.
Stalemate (neither player wins)
Description In a game of Tic Tac Toe- two players take turns making an.docx

Mais conteúdo relacionado

Semelhante a Description In a game of Tic Tac Toe- two players take turns making an.docx

#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdfaquapariwar
 
Connect4.c2. Include the string.h header file3. Declare the foll.pdf
Connect4.c2. Include the string.h header file3. Declare the foll.pdfConnect4.c2. Include the string.h header file3. Declare the foll.pdf
Connect4.c2. Include the string.h header file3. Declare the foll.pdfshakilaghani
 
You will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfYou will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfFashionColZone
 
Tic tac toe on c++ project
Tic tac toe on c++ projectTic tac toe on c++ project
Tic tac toe on c++ projectUtkarsh Aggarwal
 
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdfExercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdffms12345
 
Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)noorcon
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfudit652068
 
The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88Mahmoud Samir Fayed
 
This is an individual project, to be completed on your own. It i.docx
This is an individual project, to be completed on your own. It i.docxThis is an individual project, to be completed on your own. It i.docx
This is an individual project, to be completed on your own. It i.docxabhi353063
 
Objectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docxObjectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docxamit657720
 
The Ring programming language version 1.5.3 book - Part 58 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184The Ring programming language version 1.5.3 book - Part 58 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184Mahmoud Samir Fayed
 

Semelhante a Description In a game of Tic Tac Toe- two players take turns making an.docx (14)

#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf
 
Connect4.c2. Include the string.h header file3. Declare the foll.pdf
Connect4.c2. Include the string.h header file3. Declare the foll.pdfConnect4.c2. Include the string.h header file3. Declare the foll.pdf
Connect4.c2. Include the string.h header file3. Declare the foll.pdf
 
You will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfYou will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdf
 
Tic tac toe on c++ project
Tic tac toe on c++ projectTic tac toe on c++ project
Tic tac toe on c++ project
 
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdfExercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
 
Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)
 
python.pptx
python.pptxpython.pptx
python.pptx
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
 
Shoot-for-A-Star
Shoot-for-A-StarShoot-for-A-Star
Shoot-for-A-Star
 
The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88
 
This is an individual project, to be completed on your own. It i.docx
This is an individual project, to be completed on your own. It i.docxThis is an individual project, to be completed on your own. It i.docx
This is an individual project, to be completed on your own. It i.docx
 
Objectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docxObjectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docx
 
The Ring programming language version 1.5.3 book - Part 58 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184The Ring programming language version 1.5.3 book - Part 58 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184
 
The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184
 

Mais de theresar3

Designing the Future of Personal Fashion Kristen Vaccaro- Tanvi Agarw.docx
Designing the Future of Personal Fashion  Kristen Vaccaro- Tanvi Agarw.docxDesigning the Future of Personal Fashion  Kristen Vaccaro- Tanvi Agarw.docx
Designing the Future of Personal Fashion Kristen Vaccaro- Tanvi Agarw.docxtheresar3
 
Design and create the Context Level Data Flow Diagram and ER Diagram o.docx
Design and create the Context Level Data Flow Diagram and ER Diagram o.docxDesign and create the Context Level Data Flow Diagram and ER Diagram o.docx
Design and create the Context Level Data Flow Diagram and ER Diagram o.docxtheresar3
 
Design a database to keep data about college students- their academic.docx
Design a database to keep data about college students- their academic.docxDesign a database to keep data about college students- their academic.docx
Design a database to keep data about college students- their academic.docxtheresar3
 
Desiendny Hxperimens in Test the Hypurtosia Representing the Data Yisu.docx
Desiendny Hxperimens in Test the Hypurtosia Representing the Data Yisu.docxDesiendny Hxperimens in Test the Hypurtosia Representing the Data Yisu.docx
Desiendny Hxperimens in Test the Hypurtosia Representing the Data Yisu.docxtheresar3
 
Describe two (2) ways that a biomedical department with 3D printing ca.docx
Describe two (2) ways that a biomedical department with 3D printing ca.docxDescribe two (2) ways that a biomedical department with 3D printing ca.docx
Describe two (2) ways that a biomedical department with 3D printing ca.docxtheresar3
 
describes a phospholipid bilayer in which embedded proteins can move l.docx
describes a phospholipid bilayer in which embedded proteins can move l.docxdescribes a phospholipid bilayer in which embedded proteins can move l.docx
describes a phospholipid bilayer in which embedded proteins can move l.docxtheresar3
 
Description Create a file called -ingest_this-txt- type the following.docx
Description Create a file called -ingest_this-txt- type the following.docxDescription Create a file called -ingest_this-txt- type the following.docx
Description Create a file called -ingest_this-txt- type the following.docxtheresar3
 
Descripe Rock- Hint- this is loaded with diatoms- What are diatoms- a.docx
Descripe Rock-  Hint- this is loaded with diatoms- What are diatoms- a.docxDescripe Rock-  Hint- this is loaded with diatoms- What are diatoms- a.docx
Descripe Rock- Hint- this is loaded with diatoms- What are diatoms- a.docxtheresar3
 
Describe the advantages and disadvantages of using peer-to-peer networ.docx
Describe the advantages and disadvantages of using peer-to-peer networ.docxDescribe the advantages and disadvantages of using peer-to-peer networ.docx
Describe the advantages and disadvantages of using peer-to-peer networ.docxtheresar3
 
Describe the chemical (including chemical bonds) and physical properti.docx
Describe the chemical (including chemical bonds) and physical properti.docxDescribe the chemical (including chemical bonds) and physical properti.docx
Describe the chemical (including chemical bonds) and physical properti.docxtheresar3
 
Depreciation expense was $52-000 Use the corperase tax tates showa in.docx
Depreciation expense was $52-000 Use the corperase tax tates showa in.docxDepreciation expense was $52-000 Use the corperase tax tates showa in.docx
Depreciation expense was $52-000 Use the corperase tax tates showa in.docxtheresar3
 
Demographic Transition 1- Construct a graph of birth and death rates i.docx
Demographic Transition 1- Construct a graph of birth and death rates i.docxDemographic Transition 1- Construct a graph of birth and death rates i.docx
Demographic Transition 1- Construct a graph of birth and death rates i.docxtheresar3
 
Degree of combined leverage- Multiple Choice should be minimized by th.docx
Degree of combined leverage- Multiple Choice should be minimized by th.docxDegree of combined leverage- Multiple Choice should be minimized by th.docx
Degree of combined leverage- Multiple Choice should be minimized by th.docxtheresar3
 
Definitions- 1- Artery -Vessels transporting blood away from a heart c.docx
Definitions- 1- Artery -Vessels transporting blood away from a heart c.docxDefinitions- 1- Artery -Vessels transporting blood away from a heart c.docx
Definitions- 1- Artery -Vessels transporting blood away from a heart c.docxtheresar3
 
Define lexeme and token- For the code segment below- identify and list.docx
Define lexeme and token- For the code segment below- identify and list.docxDefine lexeme and token- For the code segment below- identify and list.docx
Define lexeme and token- For the code segment below- identify and list.docxtheresar3
 
Define lifetime budget constraint representative consume in the two-pe.docx
Define lifetime budget constraint representative consume in the two-pe.docxDefine lifetime budget constraint representative consume in the two-pe.docx
Define lifetime budget constraint representative consume in the two-pe.docxtheresar3
 
define and Explain Diversity and how organizations should manage it in.docx
define and Explain Diversity and how organizations should manage it in.docxdefine and Explain Diversity and how organizations should manage it in.docx
define and Explain Diversity and how organizations should manage it in.docxtheresar3
 
Define and Explain each one with an example - Prejudice and Discrimina.docx
Define and Explain each one with an example - Prejudice and Discrimina.docxDefine and Explain each one with an example - Prejudice and Discrimina.docx
Define and Explain each one with an example - Prejudice and Discrimina.docxtheresar3
 
Define a function named SwapValues that takes four integers as paramet.docx
Define a function named SwapValues that takes four integers as paramet.docxDefine a function named SwapValues that takes four integers as paramet.docx
Define a function named SwapValues that takes four integers as paramet.docxtheresar3
 
Deferred tax liabilities can arise from a revenue being reported on th.docx
Deferred tax liabilities can arise from a revenue being reported on th.docxDeferred tax liabilities can arise from a revenue being reported on th.docx
Deferred tax liabilities can arise from a revenue being reported on th.docxtheresar3
 

Mais de theresar3 (20)

Designing the Future of Personal Fashion Kristen Vaccaro- Tanvi Agarw.docx
Designing the Future of Personal Fashion  Kristen Vaccaro- Tanvi Agarw.docxDesigning the Future of Personal Fashion  Kristen Vaccaro- Tanvi Agarw.docx
Designing the Future of Personal Fashion Kristen Vaccaro- Tanvi Agarw.docx
 
Design and create the Context Level Data Flow Diagram and ER Diagram o.docx
Design and create the Context Level Data Flow Diagram and ER Diagram o.docxDesign and create the Context Level Data Flow Diagram and ER Diagram o.docx
Design and create the Context Level Data Flow Diagram and ER Diagram o.docx
 
Design a database to keep data about college students- their academic.docx
Design a database to keep data about college students- their academic.docxDesign a database to keep data about college students- their academic.docx
Design a database to keep data about college students- their academic.docx
 
Desiendny Hxperimens in Test the Hypurtosia Representing the Data Yisu.docx
Desiendny Hxperimens in Test the Hypurtosia Representing the Data Yisu.docxDesiendny Hxperimens in Test the Hypurtosia Representing the Data Yisu.docx
Desiendny Hxperimens in Test the Hypurtosia Representing the Data Yisu.docx
 
Describe two (2) ways that a biomedical department with 3D printing ca.docx
Describe two (2) ways that a biomedical department with 3D printing ca.docxDescribe two (2) ways that a biomedical department with 3D printing ca.docx
Describe two (2) ways that a biomedical department with 3D printing ca.docx
 
describes a phospholipid bilayer in which embedded proteins can move l.docx
describes a phospholipid bilayer in which embedded proteins can move l.docxdescribes a phospholipid bilayer in which embedded proteins can move l.docx
describes a phospholipid bilayer in which embedded proteins can move l.docx
 
Description Create a file called -ingest_this-txt- type the following.docx
Description Create a file called -ingest_this-txt- type the following.docxDescription Create a file called -ingest_this-txt- type the following.docx
Description Create a file called -ingest_this-txt- type the following.docx
 
Descripe Rock- Hint- this is loaded with diatoms- What are diatoms- a.docx
Descripe Rock-  Hint- this is loaded with diatoms- What are diatoms- a.docxDescripe Rock-  Hint- this is loaded with diatoms- What are diatoms- a.docx
Descripe Rock- Hint- this is loaded with diatoms- What are diatoms- a.docx
 
Describe the advantages and disadvantages of using peer-to-peer networ.docx
Describe the advantages and disadvantages of using peer-to-peer networ.docxDescribe the advantages and disadvantages of using peer-to-peer networ.docx
Describe the advantages and disadvantages of using peer-to-peer networ.docx
 
Describe the chemical (including chemical bonds) and physical properti.docx
Describe the chemical (including chemical bonds) and physical properti.docxDescribe the chemical (including chemical bonds) and physical properti.docx
Describe the chemical (including chemical bonds) and physical properti.docx
 
Depreciation expense was $52-000 Use the corperase tax tates showa in.docx
Depreciation expense was $52-000 Use the corperase tax tates showa in.docxDepreciation expense was $52-000 Use the corperase tax tates showa in.docx
Depreciation expense was $52-000 Use the corperase tax tates showa in.docx
 
Demographic Transition 1- Construct a graph of birth and death rates i.docx
Demographic Transition 1- Construct a graph of birth and death rates i.docxDemographic Transition 1- Construct a graph of birth and death rates i.docx
Demographic Transition 1- Construct a graph of birth and death rates i.docx
 
Degree of combined leverage- Multiple Choice should be minimized by th.docx
Degree of combined leverage- Multiple Choice should be minimized by th.docxDegree of combined leverage- Multiple Choice should be minimized by th.docx
Degree of combined leverage- Multiple Choice should be minimized by th.docx
 
Definitions- 1- Artery -Vessels transporting blood away from a heart c.docx
Definitions- 1- Artery -Vessels transporting blood away from a heart c.docxDefinitions- 1- Artery -Vessels transporting blood away from a heart c.docx
Definitions- 1- Artery -Vessels transporting blood away from a heart c.docx
 
Define lexeme and token- For the code segment below- identify and list.docx
Define lexeme and token- For the code segment below- identify and list.docxDefine lexeme and token- For the code segment below- identify and list.docx
Define lexeme and token- For the code segment below- identify and list.docx
 
Define lifetime budget constraint representative consume in the two-pe.docx
Define lifetime budget constraint representative consume in the two-pe.docxDefine lifetime budget constraint representative consume in the two-pe.docx
Define lifetime budget constraint representative consume in the two-pe.docx
 
define and Explain Diversity and how organizations should manage it in.docx
define and Explain Diversity and how organizations should manage it in.docxdefine and Explain Diversity and how organizations should manage it in.docx
define and Explain Diversity and how organizations should manage it in.docx
 
Define and Explain each one with an example - Prejudice and Discrimina.docx
Define and Explain each one with an example - Prejudice and Discrimina.docxDefine and Explain each one with an example - Prejudice and Discrimina.docx
Define and Explain each one with an example - Prejudice and Discrimina.docx
 
Define a function named SwapValues that takes four integers as paramet.docx
Define a function named SwapValues that takes four integers as paramet.docxDefine a function named SwapValues that takes four integers as paramet.docx
Define a function named SwapValues that takes four integers as paramet.docx
 
Deferred tax liabilities can arise from a revenue being reported on th.docx
Deferred tax liabilities can arise from a revenue being reported on th.docxDeferred tax liabilities can arise from a revenue being reported on th.docx
Deferred tax liabilities can arise from a revenue being reported on th.docx
 

Último

Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 

Último (20)

Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 

Description In a game of Tic Tac Toe- two players take turns making an.docx

  • 1. Description In a game of Tic Tac Toe, two players take turns making an available cell in a 3 x 3 grid with their respective tokens (either X or O). When one player has placed three tokens in a horizontal, vertical, or diagonal row on the grid, the game is over and that player has won. A stalemate occurs when all the cells on the grid have been filled with tokens and neither player has achieved a win. Write a program that emulates a Tic Tac Toe game. When you are done, a typical session will look like this: Welcome to tic-tac-toe. Enter coordinates for your move following the X and O prompts. 1 2 3 A | | ----- B | | ----- C | | X:A2 1 2 3 A |X| ----- B | | ----- C | | O:B3 1 2 3 A |X| ----- B | |O ----- C | | And so on. Illegal moves will prompt the user again for a new move. A win or a stalemate will be announced, mentioning the winning side if any. The program will terminate whenever a single game is complete. For this lab, you will be provided with a base file to work with. The base file can be downloaded from: https://github.com/victoryu/CIS35A-LabsLinks to an external site. You will add and/or modify the code, as instructed below. Do not change the overall structure of the program. Just fill in with your code at TODO and Step #. This file has the general framework of the TicTacToe class. An object of this class will represent a tic-tac-toe "board". The board will be represented internally by a two dimensional array of characters (3 x 3), and by a character indicating who's turn it is ('X' or 'O'). These are stored in the class instance variables as follows. private char[][] board; private char player; // 'X' or 'O' You will need to define the following methods: 1. A constructor: public TicTacToe() to create an empty board, with initial value of a space (' ') 2. play method public boolean play(String position) if position represents a valid move (e.g., A1, B3), add the current player's symbol to the board and return true. Otherwise, return false. 3. switchTurn method public void switchTurn() switches the current player from X to O, or vice versa. 4. won method public boolean won() Returns true if the current player has filled three in a row, column or either diagonal. Otherwise, return false. 5. stalemate method public boolean stalemate() Returns true if there are no places left to move; 6. printBoard method public void print() prints the current board 7. Use the following test code in your main method to create a TicTacToe object and print it using the printBoard method given, so as to test your code. Your printBoard method should produce the first board in the example above. public static void main(String[] args) { Scanner in = new Scanner(System.in); TicTacToe game = new TicTacToe(); System.out.println("Welcome to Tic-tac-toe"); System.out.println("Enter coordinates for your move following the X and O prompts"); while(!game.stalemate()) { game.print(); System.out.print(game.getPlayer() + ":"); //Loop while the method play does not return true when given their move. //Body of loop should ask for a different move while(!game.play(in.next())) { System.out.println("Illegal move. Enter your move."); System.out.print(game.getPlayer() + ":"); } //If the game is won, call break; if(game.won()) break; //Switch the turn game.switchTurn(); } game.print(); if(game.won()) { System.out.println("Player "+game.getPlayer()+" Wins!!!!"); } else { System.out.println("Stalemate"); } } Test the following cases: 1. A player makes a legal movement; 2. A player makes an illegal movement; 3. Player X wins 4. Player X loses 5. Stalemate (neither player wins)