Link Search Menu Expand Document
  1. Practice Exam Info
  2. Part 1: Many Interacting Classes
    1. Click here for the files
  3. Part 2: Short Exercises
    1. public static int countSyllables(String word)
    2. public static int[] expandArray(int[] arr)

Practice Exam Info

Try to complete this exam in about 2 hours of work. If you need longer, you’ll have it, but you should try to benchmark how far you get in 2 hours.

This practice exam is intended to be slightly longer than the actual exam will be. This is to try to prevent any nasty shocks or surprises when you take the actual exam.

Part 1: Many Interacting Classes

You’re designing software for a Cinema to track their showings and see how well different movies are selling. The software consists of:

  • Ritz.java, a file consisting of a main function that demonstrates how the rest of the classes will be used.
  • Movie.java, a file that contains a Movie class. Movies track their own information (name, runtime, rating) as well as their sales.
  • Theater.java, a file that contains a class for a specific Theater inside of a Cinema. (A Theater in this case is one individual room with a screen inside of a Cinema.) Theaters are basically just arrays of Movies, where the length of the array represents the number of time slots that the Theater screens any Movie at all. The element at position i inside the array of Movies represents the Movie showing at that Theater at that time.
    • Theaters should be able to add a new showing to a specific time slot and also get the Movie presently playing at a specific time slot.
  • Cinema.java, a file that contains a Cinema class. A Cinema is basically just an array of Theaters. A Cinema can sell tickets for a particular screening (i.e. a time slot in a particular Theater) and it can also add a showtime for a Movie in a particular Theater at a particular time slot.

Ritz.java is completed for you. Movie, Theater, and Cinema are provided as skeleton classes with method signatures but no method bodies. Do not change any method signatures or any fields. Fill in the bodies of the methods so that the code compiles and Ritz.java runs correctly.

NB: There are many methods to fill in, but each should only take a small number of lines to solve correctly. The challenge here is interpreting requirements and understanding interactions among classes–NOT writing intricate methods.

Click here for the files

Part 2: Short Exercises

public static int countSyllables(String word)

Use iteration and methods from the String class to count and return how many syllables are present in the input word. Assume that a syllable is any group of one or more adjacent vowels ('a', 'e', 'i', 'o', 'u').

For example:

  • "real" has one syllable, coming from the group of vowels "ea".
  • "regal" has two syllables, with the "e" being the first vowel group and "a" being the second.
  • "jfdkjjdkshfslkdfn" has no vowels, and therefore no syllables.
  • "aoieuaoueaioaueioauoiuea" has just one syllable—it’s all vowels, and they’re all consecutive.

You can assume that the input is all in lowercase. Remember that char literals, which represent individual characters, are written with single quotes ('a' and 'z', for example).

public static int[] expandArray(int[] arr)

arr is an array consisting only of non-negative ints. Return an array of ints where each element of arr appears as many times as its own magnitude suggests. For example:

  • if int[] arr = {1, 2, 3}, expandArray(arr) should return {1, 2, 2, 3, 3, 3}.
  • if int[] arr = {4, 1, 0, 3, 1}, expandArray(arr) should return {4, 4, 4, 4, 1, 3, 3, 3, 1}.
  • if int[] arr = {8}, expandArray(arr) should return {8, 8, 8, 8, 8, 8, 8, 8}.

That is, a 4 in the input array should be replaced by four 4s in the output array. 0s in the input array should not appear at all in the output array.