Introduction to programming, course exam 21 October 2009/AW Please write the name of the course, the date of the exam, your name, student number (or personal number from your SII card) and your signature at the top of each paper. Please write the answer to each problem (1, 2, 3) on a separate paper! You may write in Finnish, Swedish or English. If necessary, you may even use all these languages, as long as your replies are intelligible. 1. There are two money vaults in a foundation. One of the vaults is for money the foundation has acquired itself, the other for backing given by the government. We will call the vaults 'assets vault' and 'backing vault'. The backing vault may not be negative. The assets vault can; if it has a negative value, it means that the foundation owes money; positive means that the foundation has assets that it has acquired itself. Program the class Foundation to implement the foundation. * public Foundation(double assets, double backing) creates the Foundation object. The starting capital of the vaults is given as parameters. * public double getAssets() returns the value of the assets vault * public double getBacking() returns the value of the backing vault * public double getBalance() returns the foundation?s total balance, i.e. the sum of the vaults * public void assetChange(double amount) changes the contents of the assets vault according to the parameter, the parameter can be negative * public boolean governmentBacking(double amount) adds to the contents of the backing vault according to the parameter; only positive backing can be entered. If the government tries to take money from the foundation in the name of 'negative backing,' the method returns the value false, in other cases true. * public double transferBackingToAssets(double amount) moves as much money as the parameter determines from the backing vault to the assets vault. If the vault does not contain the amount requested, it transfers what is available. If the parameter is negative, there is no transferral -- we can't start calling assets backing. The method returns the amount transferred as its value. * public String toString() returns a plain character string presentation of the foundation's balance Illustrate the use of the class Foundation with a small main program. This program does not need to and should not read anything. Do not waste time in trying to look for a real counterpart to this Foundation class! Just program it as you are told by 'API.' (16 points) 2. Explain briefly and clearly the following concepts: parameter, constructor, accessor, encapsulation. (à 4 points, 16 points total) 3. Implement the following guessing game as an interactive, i.e. discursive, program. In the mornings, exactly one thousand lucky numbers are entered into the program in random order. The lucky numbers are positive integers. The same number may occur more than once. During the day, the players try to guess the numbers. If a player manages to guess one of the numbers that were entered in the morning, the program congratulates the player. If the player is not successful, the program offers its condolences. The program stops running when a player enters zero or a negative number as their guess. In that case, the program prints the number of correct and incorrect guesses. For efficiency, the search of numbers from the table must be programmed with a binary search. You can assume that all the input data are valid integers. (18 points)