Question: in java 7 . 2 0 ( Total Sales ) Use a two - dimensional array to solve the following problem: A company has four

in java
7.20(Total Sales) Use a two-dimensional array to solve the following problem: A company has four salespeople (1 to 4) who sell five different products (1 to 5). Once a day, each salesperson passes in a slip for each type of product sold. Each slip contains the following:
The salesperson number
The product number
The total dollar value of that product sold that day
Thus, each salesperson passes in between 0 and 5 sales slips per day. Assume that the information from all the slips for last month is available. Write an application that will read all this information for last months sales and summarize the total sales by salesperson and by product. All totals should be stored in the two-dimensional array sales. After processing all the information for last month, display the results in tabular format, with each column representing a salesperson and each row representing a particular product. Cross-total each row to get the total sales of each product for last month. Cross-total each column to get the total sales by salesperson for last month. Your output should include these cross-totals to the right of the totaled rows and to the bottom of the totaled columns.
7.21(Turtle Graphics) The Logo language made the concept of turtle graphics famous. Imagine a mechanical turtle that walks around the room under the control of a Java application. The turtle holds a pen in one of two positions, up or down. While the pen is down, the turtle traces out shapes as it moves, and while the pen is up, the turtle moves about freely without writing anything. In this problem, youll simulate the operation of the turtle and create a computerized sketchpad.
Use a 20-by-20 array floor thats initialized to zeros. Read commands from an array that contains them. Keep track of the current position of the turtle at all times and whether the pen is currently up or down. Assume that the turtle always starts at position (0,0) of the floor with its pen up. The set of turtle commands your application must process are shown in Fig. 7.29.
Fig. 7.29
Command Meaning
1 Pen up
2 Pen down
3 Turn right
4 Turn left
5,10 Move forward 10 spaces (replace 10 for a different number of spaces)
6 Display the 20-by-20 array
9 End of data (sentinel)
Turtle graphics commands.
Suppose that the turtle is somewhere near the center of the floor. The following program would draw and display a 12-by-12 square, leaving the pen in the up position:
2
5,12
3
5,12
3
5,12
3
5,12
1
6
9
As the turtle moves with the pen down, set the appropriate elements of array floor to 1s. When the 6 command (display the array) is given, wherever theres a 1 in the array, display an asterisk or any character you choose. Wherever theres a 0, display a blank.
Write an application to implement the turtle graphics capabilities discussed here. Write several turtle graphics programs to draw interesting shapes. Add other commands to increase the power of your turtle graphics language.
7.22(Knights Tour) An interesting puzzler for chess buffs is the Knights Tour problem, originally proposed by the mathematician Euler. Can the knight piece move around an empty chess-board and touch each of the 64 squares once and only once? We study this intriguing problem in depth here.
The knight makes only L-shaped moves (two spaces in one direction and one space in a perpendicular direction). Thus, as shown in Fig. 7.30, from a square near the middle of an empty chessboard, the knight (labeled K) can make eight different moves (numbered 0 through 7).
Fig. 7.30
The eight possible moves of the knight.
An 8 by 8 array where the rows and columns are numbered from 0 to 7 each. The knight is positioned on row 3, column 4. The eight possible moves for the knight are: possibility 0, row 2, column 6; possibility 1, row 1, column 5; possibility 2, row 1, column 3; possibility 3, row 2, column 2; possibility 4, row 4, column 2; possibility 5, row 5, column 3; possibility 6, row 5, column 5; possibility 7, row 4, column 6.
Draw an eight-by-eight chessboard on a sheet of paper, and attempt a Knights 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 youll get, remembering that a full tour consists of 64 moves. How far did you get? Was this close to your estimate?
Now lets 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. 7.30, 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 move

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!