Big Java, Binder Ready Version: Early Objects
6th Edition
ISBN: 9781119056447
Author: Cay S. Horstmann
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Question
Chapter 10, Problem 17PP
Program Plan Intro
Tic Tac Toe
Program plan:
Filename: “TicTacToeComponent.java”
This program file is used to define a class “TicTacToeComponent”. In the code,
- Import the required packages.
- Define a class “TicTacToeComponent”.
- Declare class members “board”, “squareDim”, “leftPad”, “topPad”, “MARK_PAD”.
- Define a constructor “TicTacToeComponent()”.
- Initialize the class members.
- Define a method “paintComponent()”.
- Draw board.
- Define a method “drawMark()”.
- If “mark” is “X”,
- Draw “line1” and “line2”.
- Else, if the “mark” is “O”,
-
- Draw circle.
- Draw “line1” and “line2”.
- If “mark” is “X”,
Filename: “TicTacToeBoard.java”
This program file is used to define a class “TicTacToeBoard”. In the code,
- Define a class “TicTacToeBoard”.
- Declare the class members “BLANK”, “X_MARK”, “O_MARK” and “board”.
- Define the constructor “TicTacToeBoard()”.
- Iterates for loops,
- Initialize “board[][]”.
- Iterates for loops,
- Define a method “availableSquare()”.
- Return the result of expression.
- Define a method “determineWinner()”.
- Iterate for loop,
- If the condition is true,
- Return the element “board[row][0]”.
- If the condition is true,
- Iterate for loop,
- If the condition is true,
- Return the element “board[0][col]”.
- If the condition is true,
- If the condition is true,
- Return element “board[0][0]”.
- If the condition is true,
- Return element “board[0][2]”
- Iterate for loop,
- Return “BLANK”.
- Define a method “getMark()”.
- If the condition is true,
- Return the element “board[row][col]”.
- Otherwise,
- Return “BLANK”.
- If the condition is true,
- Define a method “setMark()”.
- If the condition is true,
- Set “mark” to “board[row][col]”.
- If the condition is true,
- Define a method “reset()”.
- Iterate for loops,
- Set “BLANK” to “board[row][col]”.
- Iterate for loops,
- Define a method “validMark()”.
- Return the truth value of expression.
Filename: “TicTacToeFrame.java”
This program file is used to define a class “TicTacToeFrame”. In the code,
- Define a class “TicTacToeFrame”.
- Define the class members.
- Define a constructor “TicTacToeFrame()”.
- Set a variable “done” as “false”.
- Define a “board”.
- Define an object of “BoxLayout”.
- Set the layout of “panel”.
- Set the “player”.
- Define a label and set its text as “X's turn”.
- Create “component”.
- Create a “JButton” and set its text as “Reset Game”.
- Define the object of “MousePressedListener” named “listener”.
- Add mouse listener to “component”.
- Define a panel “panel2”.
- Add button to “panel2”.
- Add “turnLabel” to “panel2”.
- Add “panel2” to “panel1”.
- Add “panel1” to the layout.
- Set the size of frame.
- Define a method “selectSquare()”.
- Call “setMark()” using “board”.
- Define a method “computeRow()”.
- If the condition is “true”,
- Return “-1”.
- Return the truth value of expression.
- Return “-1”.
- If the condition is “true”,
- Define a method “computeCol()”.
- If the condition is “true”,
- Return “-1”.
- Return the truth value of expression.
- Return “-1”.
- If the condition is “true”,
- Define a method “reset()”.
- Call the method “reset()” using “board”.
- Set the “player”.
- Call the method “setTurnLabel()”.
- Set “done” equal to false.
- Define a method “switchPlayer()”.
- If “player” equal to “X_PLAYER”.
- Set “player” equal to “O_PLAYER”.
- Else,
-
- Set “player” equal to “X_PLAYER”.
- Call the method “setTurnLabel()”.
- Set “player” equal to “O_PLAYER”.
- If “player” equal to “X_PLAYER”.
- Define a method “setWinner()”.
- If “player” equal to “X_PLAYER”.
- Set text of label as “X wins!”.
- Else,
-
- Set text of label as “O wins!”.
- Set “done” equal to “true”.
- Set text of label as “X wins!”.
- If “player” equal to “X_PLAYER”.
- Define a method “setTurnLabel()”.
- If “player” equal to “X_PLAYER”.
- Set text of label as “X’s turn”.
- Else,
-
- Set text of label as “O’s turn”.
- Set text of label as “X’s turn”.
- If “player” equal to “X_PLAYER”.
- Define a method “getMark()”.
- If “player” equal to “X_PLAYER”.
- Return the value.
- Else,
-
- Return the value.
- Return the value.
- If “player” equal to “X_PLAYER”.
- Define a class “MousePressedListener”.’
- Define a constructor “MousePressedListener()”.
- Set “mouseX”.
- Set “mouseY”.
- Set “row”.
- Set “col”.
- If “true”,
- Call “selectSquare()”.
- If the condition is “true”.
-
- Call “setWinner()”.
- Otherwise,
-
- Call “switchPlayer()”.
- Call “repaint()”.
- Call “switchPlayer()”.
- Declare do nothing methods named “mouseReleased()”, “mouseClicked()”, “mouseEntered()”, “mouseExited()”.
- Define a constructor “MousePressedListener()”.
- Define a class “ResetListener”.
- Define method “actionPerformed()”.
- Call “reset()”.
- Call “repaint()”.
- Define method “actionPerformed()”.
Filename: “TicTacToe.java”
This program file is used to define a class “TicTacToe”. In the code,
- Import the required packages.
- Define a class “TicTacToe”.
- Define the method “main()”.
- Define the object of “JFrame”.
- Set the title of JFrame as “Tic-Tac-Toe”.
- Set default close.
- Set the frame as visible.
- Define the method “main()”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Big Java, Binder Ready Version: Early Objects
Ch. 10.1 -
Suppose you want to use the average method to...Ch. 10.1 - Prob. 2SCCh. 10.1 - Prob. 3SCCh. 10.1 -
What is wrong with this code?
Measurable meas =...Ch. 10.1 -
What is wrong with this code?
Measurable meas =...Ch. 10.2 -
Can you use a cast (BankAccount) meas to convert...Ch. 10.2 - Prob. 7SCCh. 10.2 -
Why is it impossible to construct a Measurable...Ch. 10.2 -
Why can you nevertheless declare a variable whose...Ch. 10.2 -
What does this code fragment print? Why is this...
Ch. 10.3 - Prob. 11SCCh. 10.3 - Prob. 12SCCh. 10.3 - Prob. 13SCCh. 10.3 -
Write a method max that finds the larger of any...Ch. 10.3 -
Write a call to the method of Self Check 14 that...Ch. 10.4 -
Suppose you want to use the average method of...Ch. 10.4 - Prob. 17SCCh. 10.4 - Prob. 18SCCh. 10.4 - Write a method max with three arguments that finds...Ch. 10.4 - Write a call to the method of Self Check 19 that...Ch. 10.5 - Why would you use an inner class instead of a...Ch. 10.5 - When would you place an inner class inside a class...Ch. 10.5 - How many class files are produced when you compile...Ch. 10.6 - Why is it necessary that the real class and the...Ch. 10.6 - Why is the technique of mock objects particularly...Ch. 10.7 - Prob. 26SCCh. 10.7 - Prob. 27SCCh. 10.7 - Prob. 28SCCh. 10.7 - Prob. 29SCCh. 10.7 - If an inner class accesses a local variable from a...Ch. 10.8 - Prob. 31SCCh. 10.8 - Prob. 32SCCh. 10.9 - Prob. 33SCCh. 10.9 - Prob. 34SCCh. 10.10 - Prob. 35SCCh. 10.10 - Why must the MousePressListener class supply five...Ch. 10 - Prob. 1RECh. 10 - Prob. 2RECh. 10 - Prob. 3RECh. 10 - Prob. 4RECh. 10 - Prob. 5RECh. 10 - The classes Rectangle2D.Double, Ellipse2D.Double,...Ch. 10 - Suppose r contains a reference to a new...Ch. 10 - Classes such as Rectangle2D. Double,...Ch. 10 - Prob. 9RECh. 10 - What happens if you try to use an array of String...Ch. 10 - Prob. 11RECh. 10 - What happens if you pass an array of strings and...Ch. 10 - Consider this top-level and inner class. Which...Ch. 10 - What happens when an inner class tries to access a...Ch. 10 - Prob. 15RECh. 10 - Prob. 16RECh. 10 - Prob. 17RECh. 10 - What is the difference between an ActionEvent and...Ch. 10 - Prob. 19RECh. 10 - Prob. 20RECh. 10 - Prob. 21RECh. 10 - Prob. 22RECh. 10 - Prob. 23RECh. 10 - Prob. 24RECh. 10 - Add a method
public static Measurable...Ch. 10 - Prob. 2PECh. 10 - A person has a name and a height in centimeters....Ch. 10 - Add static methods largest and smallest to the...Ch. 10 - In the Sequence interface of Worked Example 10.1,...Ch. 10 - In Worked Example 10.1, add a default...Ch. 10 - In Worked Example 10.1, make the process method a...Ch. 10 - Add a method to the Data class that returns the...Ch. 10 - Prob. 9PECh. 10 - Modify the Coin class from Chapter 8 to have it...Ch. 10 - Repeat Exercise E10.9, making the Measurer into an...Ch. 10 - Repeat Exercise E10.9, making the Measurer an...Ch. 10 - Implement a class Bag that stores items...Ch. 10 - Prob. 14PECh. 10 - Reimplement Exercise E10.14 where the grid is...Ch. 10 - Prob. 16PECh. 10 - Enhance the ButtonViewer program so that it prints...Ch. 10 - Prob. 18PECh. 10 - Prob. 19PECh. 10 - Prob. 20PECh. 10 - Prob. 21PECh. 10 - Prob. 22PECh. 10 - Prob. 23PECh. 10 - Reimplement the program in Section 10.7.2,...Ch. 10 - Prob. 25PECh. 10 - Prob. 26PECh. 10 - Prob. 27PECh. 10 - Prob. 28PECh. 10 - Prob. 29PECh. 10 - Prob. 30PECh. 10 - Prob. 1PPCh. 10 - Write a class PrimeSequence that implements the...Ch. 10 - Prob. 3PPCh. 10 - Prob. 4PPCh. 10 - Prob. 5PPCh. 10 - Prob. 6PPCh. 10 - Prob. 7PPCh. 10 - Prob. 8PPCh. 10 - Prob. 9PPCh. 10 - Prob. 10PPCh. 10 - Prob. 11PPCh. 10 - Prob. 12PPCh. 10 - Prob. 13PPCh. 10 - Prob. 14PPCh. 10 - Prob. 15PPCh. 10 - Prob. 16PPCh. 10 - Prob. 17PPCh. 10 - Prob. 18PPCh. 10 - Prob. 19PPCh. 10 - Prob. 20PPCh. 10 - Prob. 21PPCh. 10 - Prob. 22PPCh. 10 - Prob. 23PPCh. 10 - Prob. 24PPCh. 10 - Prob. 25PPCh. 10 - Prob. 26PPCh. 10 - Prob. 27PP
Knowledge Booster
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