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.
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 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 printBoard()
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.printBoard(); 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; game.printBoard(); //Switch the turn game.switchTurn(); } game.printBoard(); if(game.won()) { System.out.println("Player "+game.getPlayer()+" Wins!!!!"); } else { System.out.println("Stalemate"); } }
In: Computer Science
In C++, Define a structure Triangle that contains three Point members. Write a function that computes the perimeter() of a Triangle. Write a program that reads the coordinates of the points, calls your function, and displays the result.
C++
In: Computer Science
Vandelay Industries is considering the purchase of a new machine for the production of latex. Machine A costs $3,054,000 and will last for six years. Variable costs are 35 percent of sales, and fixed costs are $200,000 per year. Machine B costs $5,238,000 and will last for nine years. Variable costs for this machine are 30 percent of sales and fixed costs are $135,000 per year. The sales for each machine will be $10.2 million per year. The required return is 10 percent, and the tax rate is 35 percent. Both machines will be depreciated on a straight-line basis. The company plans to replace the machine when it wears out on a perpetual basis. |
Calculate the EAC for each machine. (Enter your answer in dollars, not millions of dollars, e.g. 1,234,567. Negative amounts should be indicated by a minus sign. Do not round intermediate calculations and round your answers to 2 decimal places, e.g., 32.16.) |
EAC | |
Machine A | $ |
Machine B | $ |
In: Finance
identify the historical periods or phases in the evolution of the international system and discuss the 4 consequences of the peace of Westphalia treaty: early idealist belief about the international system and how globalization has impacted these key principles today?
In: Psychology
A specific type of ideal gas has a specific heat capacity at constant pressure (cp=cv+R) that is a function of temperature T, such that cp=0.48T+885, where cp has units of J/kg/K and T has units of K. The gas, which is initially at T1 = 314 K and P1 = 1x105 Pa, undergoes a reversible adiabatic process such that its final temperature is T2 = 772 K. Calculate the pressure of the gas (in Pa) in this final state. Assume the following ideal gas constant: R = 287 J/kg/K. Recall that ds = cpdT/T – RdP/P
In: Physics
Draw the class diagram of University; University (name and location etc) is maintaining the student affairs, faculty or non-faculty record, student record, hostel management, route management etc. University has a chancellor and different departments. Faculty and non-faculty members are the part of each department. Minimum 2 or 3 attributes and operations of each class. Show the cardinality or multiplicity constraints as well.
In: Computer Science
Suppose there are three users: DBA, user1, user2, user3. Please specify whether user1, user2, user3 have update privilege on checking and saving table after execution of the following SQL statements.
DBA:
Grant update on checking to user1 with grant option;
Grant update on checking to user2 with grant option;
Grant update on saving to public;
Grant update on saving to user2 with grant option;
User1:
Grant update on checking to user3;
User 2:
Grant update on checking to user3;
Grant update on saving to user3;
DBA:
Revoke update on checking from user1;
Revoke update on saving from public;
In: Computer Science
Which part of the history of private security made the biggest contribution to contemporary security?
In: Psychology
Unit price: $50
Variable cost: $30
Fixed Cost: $430,000
Expected Sales: 42,000 units per year
However, you recognize that some of these estimates are subject to error. Suppose that each variable may turn out to be either 10% high or 10% lower than the initial estimate. The project will last for 10 years and requires an initial investment of $1.9 million, which will be depreciate straight line over the project life to a final value of zero. The firm’s tax rate is 35% and the required rate of return is 10%.
In: Finance
CONTEMPORARY CANADIAN BUSINESS LAW : Chapter 14, Page 260, Case 4
Awwad, a skilled carpenter, agreed to construct a garage for
Henderson for a contract price of $3,000. Henderson was to supply
the plans, foundation, and materials. Awwad constructed the garage
according to the plans. When the building had been framed, he
discovered that the siding boards that Henderson had purchased were
of poor-grade lumber. The boards could only be made to fit with a
great deal of hand labour and cutting. Awwad complained to
Henderson and demanded that he provide siding boards that were of
“construction-grade” lumber. Henderson refused to do so. An
argument followed in which Awwad refused to complete the work until
Henderson provided suitable materials. At the time of the argument,
the foundation, the roof, and the walls had been erected. The work
that remained included the installation of the wall siding, the
doors and windows, and the trim. Discuss the rights of the parties
and the nature of the claims and defences of each. Indicate the
possible outcome, if the case should come before the
courts.
In: Operations Management
Solve this question in C++ language. DO NOT use loops. Use recursive function. Keep the program simple.
Q (5) Suppose you have been given the task to design a text editor which will take any multiline text from user and then display the statistics like total number of characters i.e., characters_count (excluding the white space and punctuations), words_count, and redundant_words_count. Create a structure named Text_Editor having four type members namely inserted_text (of type string), characters_count (of type unsigned int), words_count (of type unsigned int), and redundant_words_count (of type unsigned int). The structure should also have member functions namely Insert_Text( ) for obtaining the multiline text from user and assigning to input_text member-variable. End of text insertion should be specified by ‘#’ character. Moreover, there should be a separate member-function of the created structure named Count_Ch( ), Count_Words( ), and Count_Redundant_Words( ) that should process the input text in order to calculate and print the relevant statistics. All these different tasks are to be implemented using recursion technique. (30 Points)
In: Computer Science
In a random sample of 24 fifth graders who took an IQ test, the average score was 101.48 with a standard deviation of 13.34. Assuming that the IQ scores are normally distributed, what will be the 98% confidence interval for the average IQ scores for all fifth graders?
Select the best answer.
96.3054 to 106.6546
95.5521 to 107.4079
96.8131 to 106.1469
94.6728 to 108.2872
In: Math
A certain person had a brain that weighed 1.10 kg and contained 3.51 x 10^10 cells. Assuming that each cell was completely filled with water (density = 1.00 g/mL) calculate the length of one side of such a cell if it were a cube.
If the surface were spread out into a thin layer that was a single
cell thick what would be the surface area in square meters?
In: Chemistry
Consider a project to supply 106 million postage stamps per year to the U.S. Postal Service for the next five years. You have an idle parcel of land available that cost $1,960,000 five years ago; if the land were sold today, it would net you $2,160,000 aftertax. The land can be sold for $2,360,000 after taxes in five years. You will need to install $5.46 million in new manufacturing plant and equipment to actually produce the stamps; this plant and equipment will be depreciated straight-line to zero over the project’s five-year life. The equipment can be sold for $560,000 at the end of the project. You will also need $660,000 in initial net working capital for the project, and an additional investment of $56,000 in every year thereafter. Your production costs are .56 cents per stamp, and you have fixed costs of $1,080,000 per year. If your tax rate is 34 percent and your required return on this project is 12 percent, what bid price should you submit on the contract? (Do not round intermediate calculations and round your answer to 5 decimal places, e.g., 32.16161.) |
Bid price $
In: Finance
Solve:
y'''−7y''+8y'+16y=0
y(0)=1, y'(0)=−3, y''(0)=10y(0)=1, y′(0)=-3, y′′(0)=10
y(t)= ?
In: Advanced Math