University of Helsinki / Dep. of Computer Science / Copyright © 2008 Arto Wikla.

Introduction to Programming, course examination 15.10.2008/AW

Write the name of the course, the date of the exam, your name, student number and signature on each paper. Write each answer on a separate paper!

  1. There are two money vaults in a bank. One of them is for the bank's own money, the other one for borrowed and lent money. We will call the vaults "own vault" and "loans_balance vault". The own vault may not be negative. The loans balance vault can; a negative value means that the bank owes money, a positive balance that people owe the bank money. Program the class MoneyBank to implement the bank.

    Show with the help of a small main program how the class MoneyBank is used. This program does not need to read anything. Do not waste time in trying to look for a real counterpart to this MoneyBank! Just write the program as requested.

                                                                        (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!
                                                                        (16 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 draws the 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 can generate random number in range 1-39 by the following:
         int number = (int)(39*Math.random()) + 1;
    
                                                                       
                                                                             (18 points)