|
|
Java Student Project |
||
|
|||
Prices |
|||
|
|
|
||
| Ability Level: | Beginning | ||
|
|
|
||
| Estimated Time: | 45 minutes | ||
|
|
|
||
| Objectives: |
· Learn
how to declare and initialize an Array object
· Be able to use subscripts to access elements of an Array· Understand how to declare an Array of objects· Learn to search an Array· Be able to pass an Array to a method |
||
|
|
|
||
| Materials & Resources: |
|
||
|
|
|
||
| Overview: |
An array is a list of data items that all have
the same data type and the same name. You declare an array
variable in the same way as you declare any scalar variable, but
you insert a pair of square brackets. |
||
|
|
|
||
| Instructions: |
For practice you are to write a program which
will read in an array of 20 decimal numbers. Print out all
the numbers that have a value less than 5, the average of
all the numbers, and the numbers that are larger than the
average. |
||
|
|
|
||
| Hints: | Some important
points to keep in mind in doing this project:
I. Sorting primitive array elements A. Sorting is the process of arranging objects in a logical order, either ascending, from low to high, or descending, from high to low. B. The bubble sort is a commonly used sorting technique which uses a series of comparisons and swaps to order the elements of an array. The bubble sort is suited for small arrays, but is not an efficient way to order a large amount of data.C. In the bubble sort, the largest value "falls" to the bottom of the array, (in the case of an ascending sort), after you have compared each pair of values in the array one time.II. Sorting arrays of objects A. Arrays of objects may be sorted in the same way as arrays of primitive types.. III. Sorting Strings A. When sorting an array of Strings you must use the compareTo( ) method of the String object in the comparison, rather than the > or < operator used for primitives. Otherwise the sorting process is the same as for primitive types. IV. Using two-dimensional arrays.110 A. An array may be a single column of values, a one-dimensional array, or a set of rows and columns (a multi-dimensional array).B. Multi-dimensional arrays are called matrixes and are similar to spreadsheets. C. The elements of multi-dimensional arrays are automatically initialized to zero if no values are provided. D. A multi-dimensional array may be initialized when it is created, just as with a one-dimensional array.E. Multi-dimensional arrays may have more than two dimensions, but it is up to the programmer to keep track of the indexes. V. Using StringBuffer A. A limitation of the String class is that the value of a String is fixed after the String is created. Java String objects are immutable. B. The StringBuffer class is used to create a string that may be modified. C. StringBuffers can expand or decrease in size dynamically. D. The StringBuffer class provides many methods to use in modifying strings allowing characters to be appended, inserted and manipulated similar to arrays.
|
||
|
|
|
||
| Extra: | |||