Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 8, Problem 8.9PE
Program Plan Intro
Game: play a tic-tac-toe game
Program Plan:
- Include the necessary package.
- Define the class named “Exercise08_09”.
- Declare the object “obj” for scanner class.
- Define the main method.
- Declare a variable “brd” for grid board.
- Call the method “printBoard()” to print the board on screen.
- Define the “while” loop.
- Call the method “user_move()” which takes board and symbol.
- Call the method “printBoard()”.
- Using “if…else” condition to call the function “check_Won()”.
- If the condition is true, print “X player won” statement on screen and exit the code.
- Otherwise, check the “if” condition and call the function “check_draw()”.
- Print “No winner” on screen and exit the code.
- Otherwise, check the “if” condition and call the function “check_draw()”.
- If the condition is true, print “X player won” statement on screen and exit the code.
- Define the method “user_move()” which takes board and user’s symbol.
- Declare the Boolean variable “done” and assign “false” on screen.
- Define “do…while” loop.
- Inside the loop, prompt the value of variables “row” and “column” from user.
- Using “if…else” condition, initialize the user’s symbol into board and assign “true” to variable “done”.
- Otherwise, print the statement.
- Define the method “printBoard()” which takes the board as input.
- Using “for” loop, print the board with symbols on screen.
- Define the method “check_won()” which takes character symbol and board as arguments.
- Using “for” loop and “if” condition, check the values for row, column, major diagonal, and sub diagonal grid values.
- Define the method “check_draw()” which takes board as input.
- Using “for” loops, check the grid values.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
// defining the pins
const int green_led = 3;const int red_led = 5;const int yellow_led = 6;const int buzzer = 4;const int button_status = 12;const int button_fall = 11;const int button_safe = 10;const int potentiometer = A0;
int pot_value;int button_fall_state;int button_safe_state;int last_button_fall_state;int buzzer_state;int threshold = 512;
int button_status_state = 0;
void setup() { // put your setup code here, to run once:Serial.begin(9600);// Initializing digital pins as outputpinMode(green_led, OUTPUT);pinMode(red_led, OUTPUT);pinMode(yellow_led, OUTPUT);pinMode(buzzer, OUTPUT);
// Initializing digital pins as inputspinMode(button_status, INPUT);pinMode(button_fall, INPUT);pinMode(button_safe, INPUT);// initializing analog pin as inputpinMode(potentiometer, INPUT);
digitalWrite(buzzer, LOW);digitalWrite(yellow_led, LOW);
}
void loop() { // read current state of the status button button_status_state = digitalRead(button_status);
if (button_status_state == HIGH) {…
(1)
The velocity v (m/s) of air flowing past a flat surface is measured at several
distances y (m) away from the surface. Determine the shear stress T (N/m²)
at the surface (y = 0), using Newton's viscosity law: T = u(dv/dy). Use the
following data, and provide an O(h) approximation and an O(h²)
approximation. Assume μ = 1.8 × 10-5 Ns/m². (Tip: see Fig. 23.1 for finite
difference approximations)
y (m)
0.0
0.002
0.004
0.006
0.012
v (m/s)
0.0
0.287
0.593
0.899
1.915
How to draw the decision tree using a mac book?
Can I have the instructions?
Chapter 8 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Ch. 8.2 - Declare an array reference variable for a...Ch. 8.2 - Prob. 8.2.2CPCh. 8.2 - What is the output of the following code? int[] []...Ch. 8.2 - Which of the following statements are valid? int...Ch. 8.3 - Show the output of the following code: int[][]...Ch. 8.3 - Show the output of the following code: int[][]...Ch. 8.4 - Show the output of the following code: public...Ch. 8.5 - Prob. 8.5.1CPCh. 8.6 - What happens if the input has only one point?Ch. 8.7 - What happens if the code in line 51 in Listing 8.4...
Ch. 8.8 - Declare an array variable for a three-dimensional...Ch. 8.8 - Assume char[][][] x =new char[12][5][2], how many...Ch. 8.8 - Show the output of the following code: int[][][]...Ch. 8 - (Sum elements column by column) Write a method...Ch. 8 - (Sum the major diagonal in a matrix) Write a...Ch. 8 - (Sort students on grades) Rewrite Listing 8.2,...Ch. 8 - (Compute the weekly hours for each employee)...Ch. 8 - (Algebra: add two matrices) Write a method to add...Ch. 8 - (Algebra: multiply two matrices) Write a method to...Ch. 8 - (Points nearest to each other) Listing 8.3 gives a...Ch. 8 - (All closest pairs of points) Revise Listing 8.3,...Ch. 8 - Prob. 8.9PECh. 8 - (Largest row and column) Write a program that...Ch. 8 - (Game: nine heads and tails) Nine coins are placed...Ch. 8 - (Financial application: compute tax) Rewrite...Ch. 8 - (Locate the largest element) Write the following...Ch. 8 - (Explore matrix) Write a program that prompts the...Ch. 8 - (Geometry: same line ?) Programming Exercise 6.39...Ch. 8 - (Sort two-dimensional array) Write a method to...Ch. 8 - (Financial tsunami) Banks lend money to each...Ch. 8 - (Shuffle rows) Write a method that shuffles the...Ch. 8 - (Pattern recognition: four consecutive equal...Ch. 8 - Prob. 8.20PECh. 8 - (Central city) Given a set of cities, the central...Ch. 8 - (Even number of 1s) Write a program that generates...Ch. 8 - (Game: find the flipped cell) Suppose you are...Ch. 8 - (Check Sudoku solution) Listing 8.4 checks whether...Ch. 8 - Prob. 8.25PECh. 8 - (Row sorting) Implement the following method to...Ch. 8 - (Column sorting) Implement the following method to...Ch. 8 - (Strictly identical arrays) The two-dimensional...Ch. 8 - (Identical arrays) The two-dimensional arrays m1...Ch. 8 - (Algebra: solve linear equations) Write a method...Ch. 8 - (Geometry: intersecting point) Write a method that...Ch. 8 - (Geometry: area of a triangle) Write a method that...Ch. 8 - (Geometry: polygon subareas) A convex four-vertex...Ch. 8 - (Geometry: rightmost lowest point) In...Ch. 8 - (Largest block) Given a square matrix with the...Ch. 8 - (Latin square) A Latin square is an n-by-n array...Ch. 8 - (Guess the capitals) Write a program that...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Problem 1 Write a function named initialLetterCount that takes one parameter, wordList - a list of words. Create and return a dictionary in which each initial letter of a word in wordList is a key and the corresponding value is the number of words in wordList that begin with that letter. The keys in the dictionary should be case-sensitive, which means 'a' and 'A' are two different keys. For example, the following is correct output: horton = ['I', 'say', 'what', 'I', 'mean', 'and', 'I', 'mean', 'what', 'I', 'say'] print(initialLetterCount(horton)) {'I': 4, 's': 2, 'w': 2, 'm': 2, 'a': 1} Problem 2 Write a function named initialLetters that takes one parameter, wordList – a list of words. Create and return a dictionary in which each initial letter of a word in wordList is a key and the corresponding value is a list of the words in wordList that begin with that letter. There should be no duplicate words in any value in the dictionary. For example, the following is correct output:…arrow_forwardAnswer this in hand written notearrow_forwardPlease help me wiht this and show the answer on hand writtenarrow_forward
- I need to draw the state of the memory using the specifications below and provide answers to the question. I have to do it similar to the one shown on the board if that makes any sense. All parameters are passed by reference. The language uses static scoping. What are the values of j and k after the execution of the program?arrow_forwardPlease help me wiht this and show the answer on hand writtenarrow_forwardCan you find the shortest path tree starting from vertex 3 to all other vertices for the graph below using BFSarrow_forward
- Can you find shortest path from vertex 3 to all other vertices for the graph below.arrow_forwardcan you draw the shortest path tree using BFS for the following directed unweighted graph?arrow_forwardWhat is the shortest path from vertex 3 to all other vertices:Which graph algorithm can solve the problem most efficiently(the quickest runtime)How could the same algorithm if the graph had edge weights? (create intermediate nodes)arrow_forward
- The difference between (1) a database management system (DBMS) and (2) a database, is: a. The first refers to a complete accounting system, the second refers to a subset of that b. The first is program software, the second is proprietary data and related files c. The first is hardware, the second is software d. Nothing—these terms are synonyms..arrow_forwarda) An example of the linear hash index is given below. Every time a new overflow page is added, the bucket pointed by Next is split, and Next is incremented by one. Show the index state after adding the keys 39, 25, and 29. hi ho Level=0, N=4 000 00 0*8* 001 01 17*33* 010 10 6*26* 42* 011 11 7* 11* 15* 23* 100 00 4* 12* 20* 101 01 5* 13* 21* 37* Nextarrow_forwardWhat would be the runtime (big-O asymptotic notation) of Dijkstra’s algorithm if it is implemented based on an unsorted minimum priority queue in terms of vertices (v) and edges (e)? Please show all steps including the runtime of each step of the algorithm.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education