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
Question
Chapter 15, Problem 15.36PE
Program Plan Intro
Self avoiding random walks
Program Plan:
- Create the class Lattice
- Declare and initialize the required variables.
- Define a function “Pathget()”
- Loop that iterates to set all the lattice values to be null.
- Use conditions to validate the random walk made and assign the value to the lattice values.
- Define a function “Lattice()”
- Loop that iterates to find and performs random walk 1000 times and computes the probability values.
- Display the values.
- Define a main method
- Call the function “Lattice()”
- Create the class “MyPoint”
- Declare the necessary variables
- Initialize the constructor.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Start with a pile of n stones and successively split a pile into two smaller piles until each pile has only one Each time a split happens, multiply the number of stones in each of the two smaller piles. (For example, if a pile has 15 stones and you split it into a pile of 7 and another pile of 8 stones, multiply 7 and 8.) The goal of this problem is to show that no matter how the pile of n stones are split, the sum of the products computed at each split is equal to n(n - 1)/2.
Using strong mathematical induction, prove that no matter how the pile of n stones are split, the sum of the products computed at each split is equal to n(n - 1)/2.
Idiot’s Delight is a fairly simple game of solitaire, yet it is difficult to win. The goal is to draw all of the cards from the deck, and end up with no cards left in your hand. You will run through the deck of cards one time. Start by dealing 4 cards to your hand. You will always look at the last 4 cards in your hand. If the ranks of the “outer” pair (1st and 4th) are the same, discard all four cards. Otherwise, if the suits of the “inner” pair (2nd and 3rd) are the same, discard those 2 cards only. If you have less than 4 cards, draw enough to have 4 cards in your hand. If the deck is empty, the game is over. Your score will be the number of cards that remain in your hand. Like in golf, the lower the score the better.
Create a new Python module in a file named “idiots_delight.py”. Add a function called deal_hand that creates a standard deck of cards, deals out a single hand of 4 cards and returns both the hand and the deck. Remember that for the last assignment, you created several…
Tiling: The precondition to the problem is that you are given threeintegers n, i, j, where i and j are in the range 1 to 2n. You have a 2n by 2n squareboard of squares. You have a sufficient number of tiles each with the shape . Your goalis to place nonoverlapping tiles on the board to cover each of the 2n × 2n tiles except forthe single square at location i, j. Give a recursive algorithm for this problem in whichyou place one tile yourself and then have four friends help you. What is your base case?
Chapter 15 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Ch. 15.2 - Prob. 15.2.1CPCh. 15.2 - Prob. 15.2.2CPCh. 15.3 - Why must a handler be an instance of an...Ch. 15.3 - Explain how to register a handler object and how...Ch. 15.3 - Prob. 15.3.3CPCh. 15.3 - What is the registration method for a button to...Ch. 15.4 - Can an inner class be used in a class other than...Ch. 15.4 - Can the modifiers public, protected, private, and...Ch. 15.5 - Prob. 15.5.1CPCh. 15.5 - What is wrong in the following code?
Ch. 15.6 - Prob. 15.6.1CPCh. 15.6 - What is a functional interface? Why is a...Ch. 15.6 - Prob. 15.6.3CPCh. 15.8 - Prob. 15.8.1CPCh. 15.8 - Prob. 15.8.2CPCh. 15.9 - Prob. 15.9.1CPCh. 15.9 - Prob. 15.9.2CPCh. 15.9 - Prob. 15.9.3CPCh. 15.9 - If the following code is inserted in line 57 in...Ch. 15.10 - Prob. 15.10.1CPCh. 15.11 - Prob. 15.11.1CPCh. 15.11 - Prob. 15.11.2CPCh. 15.11 - Prob. 15.11.3CPCh. 15.11 - Prob. 15.11.4CPCh. 15.12 - How does the program make the ball appear to be...Ch. 15.12 - How does the code in Listing 15.17, BallPane.java,...Ch. 15.12 - What does the program do when the mouse is pressed...Ch. 15.12 - If line 32 in Listing 15.18, BounceBall.java, is...Ch. 15.12 - Prob. 15.12.5CPCh. 15.13 - Prob. 15.13.1CPCh. 15.13 - What would happen if map is replaced by scene in...Ch. 15.13 - Prob. 15.13.3CPCh. 15 - Prob. 15.1PECh. 15 - (Rotate a rectangle) Write a program that rotates...Ch. 15 - (Move the ball) Write a program that moves the...Ch. 15 - (Create a simple calculator) Write a program to...Ch. 15 - (Create an investment-value calculator) Write a...Ch. 15 - (Alternate two messages) Write a program to...Ch. 15 - (Change color using a mouse) Write a program that...Ch. 15 - (Display the mouse position) Write two programs,...Ch. 15 - (Draw lines using the arrow keys) Write a program...Ch. 15 - (Enter and display a string) Write a program that...Ch. 15 - (Move a circle using keys) Write a program that...Ch. 15 - Prob. 15.12PECh. 15 - (Geometry: inside a rectangle?) Write a program...Ch. 15 - Prob. 15.14PECh. 15 - Prob. 15.15PECh. 15 - (Two movable vertices and their distances) Write a...Ch. 15 - (Geometry: find the bounding rectangle) Write a...Ch. 15 - Prob. 15.18PECh. 15 - (Game: eyehand coordination) Write a program that...Ch. 15 - Prob. 15.20PECh. 15 - (Drag points) Draw a circle with three random...Ch. 15 - (Auto resize cylinder) Rewrite Programming...Ch. 15 - Prob. 15.23PECh. 15 - Prob. 15.24PECh. 15 - Prob. 15.25PECh. 15 - Prob. 15.26PECh. 15 - Prob. 15.27PECh. 15 - (Display a running fan) Write a program that...Ch. 15 - (Racing car) Write a program that simulates car...Ch. 15 - Prob. 15.30PECh. 15 - Prob. 15.31PECh. 15 - (Control a clock) Modify Listing 14.21,...Ch. 15 - (Game: bean-machine animation) Write a program...Ch. 15 - Prob. 15.34PECh. 15 - Prob. 15.35PECh. 15 - Prob. 15.36PE
Knowledge Booster
Similar questions
- @nswer code to belong the code.arrow_forwardTranscribed Image Text Alex is playing Poker card game. He starts with a deck of N cards, where for each valid (i), the ith card has an integer A¡ written on it. Now the dealer starts dealing the cards one by one in the order from card 1 to card N. Alex wins if at some moment in time, the sum of all the cards dealt so far is between X and Y inclusive; if this never happens, Alex loses. You are now helping Alex to win the game, so without him noticing, you will swap some pairs of cards before the game starts. Develop a python script to find the smallest number of swaps we need so that Alex would win the game, or find that it is impossible to make Alex win. Display a single line containing one integer i.e., the smallest required number of swaps or -1 if Alex cannot win.arrow_forwardCan you show the example output?arrow_forward
- Solve and complete.arrow_forwardCorrect answer will be upvoted else Multiple Downvoted. Don't submit random answer. Computer science. Two cells are adjoining in the event that they share a side. Thusly, every cell (x, y) has precisely three neighbors: (x+1, y) (x−1, y) (x+1, y−1) in case x is even and (x−1, y+1) in any case. At first a few cells are contaminated, all the others are sound. The course of recuperation starts. Each second, for precisely one cell (despite the fact that there may be different cells that could change its state) one of the accompanying occurs: A sound cell with something like 2 contaminated neighbors likewise becomes tainted. A contaminated cell with something like 2 solid neighbors likewise becomes sound. In the event that no such cell exists, the course of recuperation stops. Patient is considered recuperated if the course of recuperation has halted and every one of the cells are solid. We're keen on a most dire outcome imaginable: is it conceivable that the patient…arrow_forwardSuppose that you are given an n × n checkerboard and a checker. You must move the checker from the bottom edge of the board to the top edge of the board according to the following rule. At each step you may move the checker to one of three squares: 1. the square immediately above 2. the square that is one up and one to the left (but only if the checker if not already in the leftmost column) 3. the square that is one up and one to the right (but only if the checker is not already in the rightmost column). 1 Each time you move from square x to square y, you receive p(x, y) dollars. You are given p(x, y) for all pairs (x, y) for which a move from x to y is legal. Do not assume that p(x, y) is positive. design a recursive backtracking algorithm that determines the maximum amount of money you can recieve, when moving a checker frmo somewhere on the bottom row to somewhere on the top row. your algorithm is free to pick any squrre along the bottom row as a starting point and any square along…arrow_forward
- Wo Home I(O noPHP) I Homework 10 Q2 Q1 Q3 L Q4 Q5 Q6 (a) Q7 Q8 Q9 Q10 (x = L, y = 0) |(x = 0, y = 0) (b) A beam is subjected to a linearly increasing distributed load. The elastic curve (deflection) is shown in the figure. The equation to find the maximum deflection is given below. Create a matlab code where you can calculate the maximum deflection (dy/dx=0) using the bisection method. Use initial guesses of 1 and 5, L= 6.27 m, E = 73000 kN/cm2, I=38000 cm4, and w0= 2.5 kN/cm. What will be the value of x (location of maximum deflection) after 15 bisection iteration? wo -(-æ³ +2L²x³ – L^x) 120EIL dy de wo (-5xª + 6L²x² – Lª) 120EIL Choices 2.5236 1.402 2.804 4.206 Submit I Attempts 1 |arrow_forwardGoing missing Some calculations involving blank values may give different results to what you might expect. For example, when you pass a blank value into the AND() function, it is treated as TRUE. This is often unhelpful. To make blanks behave in a sensible way in calculations, you must first convert them to be "not available" using NA(). This function takes no inputs, and returns a missing value. To convert a blank value to a missing value, use this pattern. =IF(ISBLANK(cell), NA(), cell) Instruction In column H, use AND() to find women who have kids and get benefits. In column I, convert the blanks in column G to missing values. In column J, again find women who have kids and get benefits, this time using column I rather than G. please show the formula used to "has kids and gets benefits" , "gets benefits with missing values", has kids and gets benefits". Thank you Is non-white Has over 12 years of school? Is married? Has kids? Has young kids? Is head of household? Gets…arrow_forwardOne variation on the game of nim is described in Luger. The game begins with a single pile of stones. The move by a player consists of dividing a pile into two piles that contain an unequal number of stones. For example, if one pile contains six stones, it could be subdivided into piles of five and one, or four and two, but not three and three. The first player who cannot make a move loses the game. (5.1) Draw the complete game tree for this version of Nim if the start state consists of six stones. (5.2) Perform a minimax evaluation for this game. Let 1 denote a win and 0 a loss.arrow_forward
- @1st mp. 109.arrow_forwardI need the answer as soon as possiblearrow_forward(b) The Fibonacci numbers for n 0, 1,...are defined as follows. fib (0)-0 fib (1) 1: fib (n) fib (n- 1) + fib (n - 2): Consider the following piece of code that calculates the Fibonacci numbers. int fib ( int n){ if (n is 0) return 0 else if (n is 1) return 1 else return fib (n- 1)+ fib (n- 2) What is the worst-case complexity of the above code?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr