University of Helsinki / Dep. of Computer Science / Introduction to Programming / Copyright © 2004 Arto Wikla.

581325-0 Introduction to Programming, course examination 12.11.2004/AW

Write the name of the course, the date of the exam, your name, personal number and signature on each paper. Write each answer on a separate paper! You are allowed to use the tools of the Lue-class (or Read-class) for reading the input.
  1. A certain Oil Reserve comprises of two oiltanks; the utility tank and the back-up tank. On the first hand oil is added to the back-up tank. Oil is added to the utility tank only, is the back-up tank is already full. On the first hand oil is taken from the utility tank. Oil can be taken from the back-up tank only if the user access is permitted.

    Create class OilReserve to implement the functionality of the Oil Reserve described above. (The constructor and accessors interpret negative parameter values as zero. Don't implement the silos as TinyStore-objects!)

                                                               (16 points)
    
  2. "What in the world are those method things?" , your friend wails when hearing your stories of the course Introduction to Programming. Your friend has programmed enough to know simple variables, expressions and statements. "What the heck are 'parameters', who is 'calling' and whom, why?, he goes on in despair. Help your friend understand what it is all about. Draw up a written description (1 exam paper at the most). Keep in mind that examples aid learning. In the evaluation of your answer, we will take into account the intended reader of the description, so do not write for the examinator, who already knows about it, but for that friend!
                                                                (16 points)
    
    1. Explain shortly, exactly and by giving examples the following concepts: array variable, array object and indexing.
                                                                  (9 points)
      
    2. Implement the following guessing game as an interactive program. Before the game starts the program draws 10000 integers into an array. The values must be in the range 0-9999. Same number may occur also several times.
      Hint: One such number can be drawn by the expression (int)(Math.random()*10000)

      Then the player starts to use the program. The player tries to guess the numebers that there are in the array. The game ends, when the player has guessed three different numbers. The result - which is also printed - is the number of guesses, so it is at least three. For the sake of efficiency, the search of the guessed numbers must be programmed with the Binary Search

                                                                  (9 points)