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

581325-0 Introduction to Programming, course examination 17.10.2005/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!
  1. A juice automata has two tanks: one for water and one for concentrated juice. Juice is produced by mixing 1/10 concentrated juice with 9/10 water.

    Implement the juice automata as a class JuiceAutomata. (The constructor and accessors interpret negative parameter values as zero.)

    Program also a main method to show, how the constructor and the methods are used.

                                                               (16 points)
    
  2. "Object? What the heck is an object? And what in the world is encapsulation?", our friend asks after listening to your stories about the course Introduction to Programming. Your friend has done a little programming, enough to know primitive variables, expressions, statements, methods and parameters, but he does not know a thing about object oriented programming. Help your friend understand what objects are, how they are programmed and used, and why they are useful. Write an explanation (maximum length is 1 sheet of paper, 4 pages). Please keep in mind that drawings and examples are a great help in learning. When evaluating the answer, we will take into account the intended reader, so do not write for the evaluator, who already knows about objects, but for that friend of yours!
                                                                (18 points)
    

  3. Lottery is a game of chance, where 7 winning numbers and 3 extra numbers are pulled randomly out of 39 possible numbers that range from 1 to 39. To place a bet you would name 7 numbers that you want to bet, out of the 39 possible numbers. To find out if you win a prize your bets are compared against the set of winning numbers. Prize categories are: 7 winning numbers right, 6 winning numbers + 1 extra number right, 6 winning numbers right, 5 winning numbers right and 4 winning numbers right.

    Write a program that first reads in a set of winning numbers. After that the program can be used to check lottery bets. Several bets can be checked. Design by yourself how to quit the program.

    You may assume that all the input is numeric, actually integer numbers. Anyhow the values should be checked and errors reported. (It might be a good idea to program an auxiliary method to check the input numbers. Perhaps a method for reading whole Lotto row could be useful?)

                                                                (16 points)