Question: in java 7 . 2 0 ( Total Sales ) Use a two - dimensional array to solve the following problem: A company has four
in java
Total Sales Use a twodimensional array to solve the following problem: A company has four salespeople to who sell five different products to 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 and 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 twodimensional 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. Crosstotal each row to get the total sales of each product for last month. Crosstotal each column to get the total sales by salesperson for last month. Your output should include these crosstotals to the right of the totaled rows and to the bottom of the totaled columns.
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 by 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 of the floor with its pen up The set of turtle commands your application must process are shown in Fig.
Fig.
Command Meaning
Pen up
Pen down
Turn right
Turn left
Move forward spaces replace for a different number of spaces
Display the by array
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 by square, leaving the pen in the up position:
As the turtle moves with the pen down, set the appropriate elements of array floor to s When the command display the array is given, wherever theres a in the array, display an asterisk or any character you choose. Wherever theres a 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.
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 chessboard and touch each of the squares once and only once? We study this intriguing problem in depth here.
The knight makes only Lshaped moves two spaces in one direction and one space in a perpendicular direction Thus, as shown in Fig. from a square near the middle of an empty chessboard, the knight labeled K can make eight different moves numbered through
Fig.
The eight possible moves of the knight.
An by array where the rows and columns are numbered from to each. The knight is positioned on row column The eight possible moves for the knight are: possibility row column ; possibility row column ; possibility row column ; possibility row column ; possibility row column ; possibility row column ; possibility row column ; possibility row column
Draw an eightbyeight chessboard on a sheet of paper, and attempt a Knights Tour by hand. Put a in the starting square, a in the second square, a in the third, and so on Before starting the tour, estimate how far you think youll get, remembering that a full tour consists of 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 eightbyeight twodimensional 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 as shown in Fig. consists of moving two squares horizontally to the right and one square vertically upward.
A move of type 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
