Introduction to programming, course exam 19 Oct 2010/AW At the top of each paper, please write the name of the course and the date of the exam, your name, student number (or SII number), and your signature. Write each reply (1, 2, 3) on its own paper! You may reply in Finnish, Swedish or English. If necessary, you may even use all of these languages, as long as your replies are intelligible. 1. a) An account with an overdraft facility can be positive or negative. Only even Euros are kept in the acocunt. Implement the charge account as the class ChAc. ChAc-API: * public ChAc() creates the object ChAc, with the initial balance of 0 Euros. * public ChAc(int saldo) creates the object ChAc, to which the initial balance is given as input. * With the accessor deposit, you can deposit money in the account. * With the accessor withdraw, you can withdraw money from the account. * The accessor balance returns the current balance of the account as its value. b) A foundation has two accounts. One account is for its own money, the other one for support funds from the Slot-Machine Association. Let us call the accounts "assets" and "backing". The backing account can never be empty. The assets account may even be negative. If the account is negative, it means that the foundation owes money, if it is positive, the foundation has money. Program the class Foundation to implement the foundation. To implement the accounts, you must use the class ChAc from problem a. Foundation-API: * public Foundation(int assets, int backing) creates the object Foundation. The initial balance of its accounts are given as parameters. * getAssets, getBacking and getBalance return as their values the account information of the foundation. The last refers to the overall status of the foundation, i.e. the sum of the accounts. * public void capitalchange(int amount) changes the balance of the assets account according to the parameter. * public boolean backingComing(int amount) adds to the backing account according to the parameter; only positive backing is accepted. If the Slot-Machine Association tries to take away money from the foundation as "negative backing", the method will not change the balance and will return the value false, otherwise the method returns true. * public int transferBackingToAssets(int amount) moves money from the backing account to the assets account according to the parameter. If there is not enough money in the account to transfer the requested amount, what is there, is transferred. If the parameter is negative, no transfer is made - we can't call assets backing, can we? As its value, the method returns the amount transferred. * public String toString() returns as its value a plain string representation of the foundation's status. c) Illustrate how to use the class Foundation by implementing the class FoundationPresentation with a main program that presents the all-round use of the class Foundation. The program does not need to read anything. (15 points) 2. Give clear explanations of the concepts parameter, overloading, encapsulation. Give illustrating examples. (9 points) 3. Create a program that first asks for the number of integers to be input, then reads that number of integers into an array, and finally offers the following service: One integer at a time is fed into the program, and the program finds out whether that integer is in the array. It must use binary search to find the answer. You may assume that all the input is valid and acceptable. (12 points)