touque.ca > Education Commons > Java > Assignments > Arrays

Arrays

  1. Exercises I
  2. Exercises II
  3. Assignments
  4. Arrays of Objects I

Exercises I

  1. Gather numeric values and then display them in reverse order.
  2. Gather marks and then display them and their mean. Reject marks which are out of range.
  3. Gather marks and then display the highest and lowest.
  4. Gather marks and then display them with the highest and lowest identified in some way. (Note: Do not display the highest and lowest after the display of all marks.)
  5. For a class of fixed size, gather marks for two different assignments and then display the mean of each assignment.
  6. For a class of fixed size, gather marks for two different assignments and then display the two marks of each student. Identify the highest and lowest mark obtained on each assignment.
  7. For a class of fixed size, gather marks for two different assignments. For each student, display the two marks with the higher mark identified in some way. For each assignment, display the mean with the higher mean identified in some way.
  8. For a class of fixed size, gather marks for two different assignments. For each student, display each mark along with that mark’s difference from the mean of its assignment. For each assignment, display the mean and the mean difference-from-the-mean.
  9. For a class of fixed size, gather marks for a fixed number of assignments. For each student, display each mark along with that mark’s difference from the mean of its assignment; the highest and lowest mark; and the marks with the least and greatest difference from their respective means. For each assignment, display the mean and the mean difference-from-the-mean. Identify the assignment whose mean is highest and whose mean is lowest.

Exercises II

  1. Gather 10 integers from the user and store them in an array.
  2. Display the 10 integers.
  3. Display the 10 integers in reverse order of entry.
  4. Display only the positive integers.
  5. Display only the negative even integers.
  6. Display the sum of the integers.
  7. Modify the array so that each element, after the first element, contains the sum of the previous element and the current element.
  8. Gather 10 words from the user and store them in an array.
  9. Display the words, one per line.
  10. Display the words on one line as if they comprised a sentence (remember that sentences start with a capital letter and end with a period; you may need to use some string methods).
  11. Gather 10 sentences from the user and store them in an array.
  12. Ask the user which sentence s/he wants, and display it; repeat until the user says so.
  13. Gather 10 words from the user, store them in an array, and then write the words to a file.
  14. Read 10 word from a file into an array, then read 10 more words from the user and add them—one to each element—to the array.

Assignments

  1. Implement a version of the Purse class with a single array called coin. Arbitrarily assign an element to hold the number of dimes, another element to hold the number of nickels, and a third to hold the number of quarters.
  2. Implement method coinMatch(int) which returns the names of coins whose numbers match int.
  3. Implement method coinMost() which returns the name of the coin whose number is greatest. Be sure to handle ties.
  4. Implement method coinLeast().
  5. Create a modification of the Purse class called BigPurse. A BigPurse does not have accessors and mutators for specific coins. Instead, a BigPurse has an addCoin(int, int) method and a getCoin(int) method. The addCoin(int, int) method accepts both a code representing the coin’s denomination and the number of coins of that denomination to be added. The getCoin(int) method accepts a coin-denomination code. Implement the codes as public constants.

Arrays of Objects I

  1. Gather an arbitrary positive integer, array size, from the keyboard and create an array of SimpleObjects of size array size whose elements are populated with data from the keyboard.
  2. Implement a static display(SimpleObject[]) method to display the contents of the array.
  3. Implement a static store(SimpleObject[], textFile) method to store the array to a text file.
  4. Implement a static retrieve(textFile, SimpleObject[]) method to populate an array with data found in a text file.
  5. Implement method compareTo(SimpleObject). object1.compareTo(object2) returns:
    • a negative value if object1 should come before object2
    • 0 if object1 and object2 are the same
    • a postive value otherwise
  6. Retrieve an array from a file. Create a SimpleObject from keyboard data. Implement a static int method linearSearch(SimpleObject[], SimpleObject) which returns the index of the simple object if it appears in the array or a negative value if the simple object does not appear in the array.

touque.ca > Education Commons > Java > Assignments > Arrays

[This page last updated 2020-12-23 at 12h12 Toronto local time.]