| CSCI A201/A597Lab Notes 13 Spring 2000 |
Sample Problem 1.
Write a program toAllow the user to specify the size of the array in the beginning and to restart the process over and over again if (s)he so desires. The user interface should be through a drawing window with buttons like in assignment 8 part 10.
- generate a certain number of random integers,
- place them in an array,
- show the array,
- sort the array (descending or ascending, as the users wants) and
- show the sorted array to the user again.
Write a program that defines, allocates and initializes a two dimensional array of integers. Then find the maximum among the array elements. Display the array as a grid of gray squares where for each cell in the grid the intensity of the color is the ratio between the number in the cell and the max value in the array. Check out 4.4.1. in your text for color functions.
Implement a game similar to the packing bin assignment with the following differences: assume a circular bin and provide rectangles instead of circles for the user to place them. When you place the rectangle check only if it falls inside the circular bin, and if it does not send it back to the starting location otherwise place it.
Write a method that computes pi by throwing n
darts. Each dart is randomly thrown at a two hundred by two hundred
pixel square. It is a hit if it is within 100 pixels of the center. An
approximation of pi is determined by dividing the number of hits
by four times the number of darts.
Implement the Tetris-like game in which random rectangles are used rather than random sized circles.
Write a program that generates a certain number of random sized rectangles, places them on the screen and allows the user to move them around with the mouse, one at a time.
Write a procedurereversethat reverses the sequence of elements in an array. For example ifreverseis called with an array containing:1 4 9 16 9 7 4 9 11then the array is changed to11 9 4 7 9 16 9 4 1
Write a functionthat appends one array after another. For example, ifint[] append(int[] a, int[] b)ais1 4 9 16andbis9 7 4 9 11thenappendreturns the array1 4 9 16 9 7 4 9 11
Write a predicate functionthat checks whether two arrays have the same elements in the same order.boolean equals(int[] a, int[] b)
Write a procedurethat displays a bar chart of the values invoid barChart(double[] data)data. You may assume that all values indataare positive. Hint: you must figure out the maximum of the values indata. Set the coordinate system so that the x-range equals the number of bars and the y-range goes from 0 to maximum.
Write a loop that fills an array v with ten random numbers between 1 and 100
and then reports the maximum and the minimum in the array. Write Java code for a loop that
simultaneously computes the maximum and the minimum of an array.
Write a functionthat computes the scalar product of two mathematical vectors (represented as arrays). The scalar product isdouble scalarProduct(double[] a, double[] b)a0b0 + a1b1 + ...an-1bn-1
Write a function that computes the alternating sum of all elements in an array. For example, ifalternatingSumis called with an array containing1 4 9 16 9 7 4 9 11then it computes1 - 4 + 9 - 16 + 9 - 7 + 4 - 9 + 11 = -2
Write a program that plays tic-tac-toe. The tic-tac-toe game is played on a 3 x 3 grid as in
![]()
The game is played by two players, who take turns. The first player marks moves with a circle, the second with a cross. The player who has formed a horizontal, vertical, or diagonal sequence of three marks wins. Your program should draw the game board, accept mouse clicks into empty squares, change the players after every successful move, and pronounce the winner.
Write a program that computes the mean (average) and standard deviation of a set of values located in an array. The average of a data setis equal to the sum of the elements divided by how many they are, and the standard deviation is the square root of the sum of the squared differences between the individual values and their average divided by their number minus 1:
![]()
These problems will be refined in the next few days and will be the starting point in producing the actual problems that you will get on the practical. If you know how to solve these problems you will probably do well on the exam. We will make sure that the problems that can appear on the exam will be all of the same difficulty. Distribution of problems will be through QuizSite in the exact same way it was done for the first practical exam.