Wednesday July 19, 2000


Quiz 25


1. In what package are the wrapper classes found?

2. What is the syntax used for declaring a new array?

3. How do we reference the first element in an array?

4. What two peices of information do we need in order to access an element in an array?
































Your second exam will be composed of the following peices.

10% Matching
20% Fill in the Blank
20% Short Answer
30% Discussion
20% Coding

Recall some of the problems we looked at yesterday.

  • Read a line in from a file, tokenize that line, and place the tokens you find into a String array.

  • Create an array whose elements are 5-minute blocks of time from 7:00 am to 11:00 pm. For times after Noon we will use military time.

    For example the array should contain the following.

    times[0]  = 700;
    times[1]  = 705;
    times[2]  = 710;
    times[3]  = 715;
    times[4]  = 720;
    times[5]  = 725;
    times[6]  = 730;
    times[7]  = 735;
    times[8]  = 740;
    times[9]  = 745;
    times[10] = 750;
    times[11] = 755;
    times[12] = 800;
    ...
    
  • Rewrite the Sieve of Eratosthenes using an array? Do you find it much easier?
    Arrays can be initialized at the time of their declaration by using the following syntax.

    data-type[] arrayname = { list of elements seperated by commas };
    
    For example to create an array of 5 ints each initialized to 1 we could use the statement

    int[] numbers = {1,1,1,1,1};
    
    Recall that all of the elements in an array must be of the same type. However, when we stored object names in an array we are not actually storing the object we are storing the reference to an object. It is important to keep in mind the difference between an object and an object reference.

    When elements such as ints are placed into an array there are a couple of things that we are able to do with those numbers. One of those is sorting and the other is searching.
    Your final programming assignment

    Your final program will involve two parts. You will prompt the user for which part they want to execute.

    The first option that you will give the user is to have you sort an array of randomly generated ints between 0 and a certain number. They will input how many numbers you should generate and what the maximum number to be generated is. For example, they might ask you to produce 20 random ints between 0 and 500. You will sort the array and determine the following information.

    The minimum number generated.

    The maximum number generated.

    The number of prime numbers generated.

    The number of even numbers generated.

    The number of odd numbers generated.

    The minimum prime number generated.

    The maximum prime number generated.

    The sum of all prime numbers generated.

    You may produce random numbers using the Math.random() method. It returns a double between 0.0 and 1.0. So to produce a random number between 0 and a certain number, you would multiply the result of Math.random() by that number and cast it as an int.

    The second option that you will present to the user will be for you to produce a table of logarithms for them. The table will be stored in a two-dimensional array.

    The rows in the array will represent tenths of numbers, that is, the first row will represent 1.0, the second row will represent 1.1, the third row will represent 1.2, etc. The last row in the array will represent 10.0.

    The columns in the array will represent hundreths of numbers up to 0.09. That is the columns will represent the numbers 0.00, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, and 0.09.

    The user will input what base to use, and each entry in the array will be the logarithm to that base of the sum of the numbers represented by the row and column.

    For example, the first entry in the table will the logarithm to the base of the input number of 1.0 + 0.00.

    The logarithms can be computed using the Math.log() method and the change of base formula



    When the logarithms are produced, truncate them to 3 decimal places.

    Then prompt the user for a filename to use and write the table to that file.