Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hey there , i was testing the some codes of the solution book of (Java 9th deitel) , and there are some troubels with this

Hey there , i was testing the some codes of the solution book of ("Java 9th deitel") , and there are some troubels with this chapter , first of all , code of exercise 25 (chapter 7) is missing , and the codes of exercise 22 (chapter 7) are able to run , but doesnt do what they are expected to do , for example , this is the code of exercise 22 chapter 7 A , the code run , but literraly , dont display nothing.

image text in transcribed

package nada; import java.awt.*; import javax.swing.*; public class NADA extends JApplet { int filaactual, columnaactual, numeromovimiento; int tablero[][]; int pruebafila, pruebacolumna, tipomovimiento; int horizontal[] = { 2, 1, -1, -2, -2, -1, 1, 2 }; int vertical [] = { -1, -2, -2, -1, 1, 2, 2, 1 }; boolean hecho, buenmovimiento; JTextArea tour; @Override public void init () { tablero = new int[ 8 ][ 8 ]; filaactual = ( int ) (Math.random() * 8 ); columnaactual = ( int ) (Math.random() * 8 ); tablero[ filaactual ][ columnaactual ] = ++numeromovimiento; hecho = false; tour = new JTextArea( 20, 30); Container container = getContentPane(); container.add( tour ); } public void comenzar() { while ( !hecho ) { tipomovimiento = 0; pruebafila = filaactual + vertical [ tipomovimiento ]; pruebacolumna = columnaactual + horizontal [tipomovimiento]; buenmovimiento = movimientovalido( pruebafila, pruebacolumna ); if (buenmovimiento) { filaactual = pruebafila; columnaactual = pruebacolumna; tablero[filaactual][columnaactual]= ++numeromovimiento; } else { for ( int count = 0; count = 0 && fila = 0&&columna Chapter 7, Problem 22E Bookark Show all steps: ON Chapter 7 6E a) Draw an eight-by-eight chessboard on a sheet of paper, and attempt a Knight's Tour by hand. Put a 1 in the starting square, a 2 in the second square, a 3 in the third, and so on. Before starting the tour, estimate how far you think you'll get, remembering that a full tour consists of 64 moves. How far did you get? Was this close to your estimate? TE 8E 9E b) Now let's develop an application that will move the knight around a chessboard. The board is represented by an eight-by-eight two-dimensional array board. Each square is initialized to zero. We describe each of the eight possible moves in terms of its horizontal and vertical components For example, a move of type 0, as shown in Fig., consists of moving two squares horizontally to the right and one square vertically upward. A move of type 2 consists of moving one square horizontally to the left and two squares vertically upward. Horizontal moves to the left and vertical moves upward are indicated with negative numbers. The eight moves may be described by two one-dimensional arrays, horizontal and vertical, as follows: 10E 11E 12E 13E 14E 1SE horizont 2 vercicalroj vercical1 vercical121 vertical3 verzicalt41 erica52 vertical[62 vertical171 orizontal11 16E horizontal[2]-1 orizontal3]-2 sorizontal4 17E sorizontall5]-1 sorizontal 1 sorizontal17 2 Let the variables currentRow and currentcolumn indicate the row and column, respectively, of the knight's current position. To make a move of type moveNumber, where moveNumber is between 0 and 7, your application should use the statements currentRoW+vertical[moveNumber] currentColumn +# horizontal[moveNumber]. Write an application to move the knight around the chessboard. Keep a counter that varies from 1 to 64. Record the latest count in each square the knight moves to. Test each potential move to see if the knight has already visited that square. Test every potential move to ensure that the knight does not land otf the chessboard. Run the application. How many moves did the knight make? 18E 19E 20E 21E 22E 23E 24E 25E

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Real Time Database And Information Systems Research Advances

Authors: Azer Bestavros ,Victor Fay-Wolfe

1st Edition

1461377803, 978-1461377801

More Books

Students also viewed these Databases questions

Question

Write formal and informal proposals.

Answered: 1 week ago

Question

Describe the components of a formal report.

Answered: 1 week ago

Question

Write formal and informal reports.

Answered: 1 week ago