Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
bartleby

Concept explainers

bartleby

Videos

Question
Book Icon
Chapter 8, Problem 8.20PE
Program Plan Intro

Game: connect four

Program Plan:

  • Define the class named “Exercise08_20”.
    • Define the “Scanner” object “obj” for input.
    • Define main method.
      • Declare the two dimensional array “brd” in type of character.
      • Call the “print_board()” method to print default board.
      • Using “while” loop,
        • Call the “Disk_drop()” method which passes “R” and “brd” as parameter.
        • Print the board.
        • Using “if…else” condition, call the methods and print appropriate statement on screen.
        • Call the “Disk_drop()” method which passes “Y” and “brd” as parameter.
        • Print the board.
        • Using “if…else” condition, call the methods and print appropriate statement on screen.
    • Define the method “Disk_drop()” which passes “player” and “brd[][]” as parameters.
      • Declare the Boolean variable “done” and assign “false” into it.
      • Using “do…while” loop,
        • Prompt and get the input for “column” from user.
        • Call the method “Disk_place()” which passes board “brd”, column “column”, and player “player” as parameter in “if” condition.
          • Assign “true” to variable “done”.
        • Else print appropriate statement on screen.
    • Define the method “Disk_place()” which passes board “brd”, column “col”, and player “player” as parameter.
      • Using “for” loop, assign value of “player” into “brd[][]”.
      • Return appropriate Boolean value.
    • Define the method “print_board()” which passes board “brd[][]” as parameter.
      • Using “for” loops, print the board on screen.
    • Define the method “isWon()” which passes board “brd[][]” as parameter.
      • Call the method “isConsecutiveFour()” method which passes “brd” as parameter and return the resultant value.
    • Define the method “isDraw()” which passes board “brd[][]” as parameter.
      • Using “for” loops, check the board value and pass the resultant value.
    • Define the method “isConsecutiveFour()” which passes “values[][]” as parameter.
      • Declare and initialize the variables “numberOfRows” and “numberOfColumns” in type of integer.
      • Using “for” loops check rows, columns, major diagonal for lower part, major diagonal for upper part, sub diagonal for left part, sub diagonal for right part, major diagonal for upper part.
        • Return the appropriate value to calling function.
    • Define the method “isConsecutiveFour()” which passes “val[]” as parameter.
      • Using “for” loops check the values of board and return the resultant value.

Blurred answer
Students have asked these similar questions
Assume you are playing a card game using a standard 52-card deck. You are dealt a hand of cards that are all the same suit, hearts. You are dealt first a 5, then a 3, then 8, and finally 4. You first grab the 8. Next you grab the 5 and place it in front of the 8. Then you take the 4 and place it in front of the 5. Finally, you take the 3 and place it in front of the 4. Which sorting algorithm is most similar to how you sorted your hand?Group of answer choices 1.Merge Sort 2.Selection Sort 3.Quick Sort 4.Insertion Sort
(PLEASE USE JAVA AND JFRAME GUI) Game rules:The game consists of a two-dimensional field of size m × n (game field). Each element ofthe game field is a button with a number assigned to it.Initialization of the game:• The numbers on the buttons of the game field are set to a random digit between 0and 9• The target value is displayed above the game field• The current sum of the numbers displayed on the buttons of the game field is printedbelow the game field• The number of moves to completion is displayed in the upper right corner above thegame field.Playing:The first move is determined by the player by selecting any button (button A) on thegame field.1. The player is allowed to choose a second button (button B) located in the columnor row of the previously selected button (A).2. Upon selecting the second button (B), the value of button (A) is updated accordingto the following formula: A = (AoperationB)mod10.3. The operation for the basic game will be +.4. Decrement the number of moves…
PLEASE CODE IN PYTHON The Penny Pitch game is popular in amusement parks. Pennies are tossed onto a board that has certain areas marked with different prizes. For example: The prizes available on this board are puzzle, game, ball, poster, and doll. At the end of the game, if all of the squares that say BALL are covered by a penny, the player gets the ball. This is also true for the other prizes. The board is made up of 25 squares (5 x 5). Each prize appears on three randomly chosen squares so that 15 squares contain prizes.In Python, create a PennyPitch application that displays a Penny Pitch board (use [ and ] to indicate squares) with prizes randomly placed and then simulates ten pennies being randomly pitched onto the board. After the pennies have been pitched, the application should display a message indicating which prizes have been won, if any.

Chapter 8 Solutions

Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package

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
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Literals in Java Programming; Author: Sudhakar Atchala;https://www.youtube.com/watch?v=PuEU4S4B7JQ;License: Standard YouTube License, CC-BY
Type of literals in Python | Python Tutorial -6; Author: Lovejot Bhardwaj;https://www.youtube.com/watch?v=bwer3E9hj8Q;License: Standard Youtube License