581325-0 Introduction to Programming, course examination 14.11.2003/AW Write the name of the course, the date of the exam, your name, personal number and signature on each paper. 1. "What in the world is encapsulation?" your friend asks after listening to your stories about the course Introduction to Programming. Your friend has done a little programming, enough to know variables, expressions, statements and methods. He has even managed to program some primitive classes for creating objects. "But what do you 'encapsulate' and what ever for?", he asks you. Help your friend understand what it is all about. Write an explanation (a maximum of one sheet). Please keep in mind that examples are a great aid to learning. When evaluating the answer, we will take into account the intended reader, so do not write for the evaluator, who already knows the subject, but for that friend of yours! (16 points) 2. There are two fuel tanks at the gas station. You can only add gas directly to the main tank, and clients can only take out gas from the main tank. The second tank is a reserve tank, which is used automatically when the capacity of the first tank runs out. Write the class GasStation to implement the gas station. - public GasStation (double mainTank, double reserveTank) creates the gas station, the parameters given are the capacities of the tanks. If there is an error in the capacity, the capacity of the tank is set to 5000 litres. Both tanks are empty to begin with. - public double main tankContains() returns the amount of gas in the main tank - public double reserveContains() returns the amount of gas in the reserve tank - public double totalGas() returns the total amount of gas in the gas station - public boolean addGas(double amount) adds gas to the main tank. If you try to add more than the tank's capacity, the excess gas is pumped into the reserve tank. If the total amount added is more than the total capacity of the tanks, the amount of gas does not change in either tank. The method returns true if the gas is added, false if it is not. - public double fillupGas(double amount) takes gas out of the main tank. If the request is for more than there is in the main tank, gas can be transferred automatically from the reserve tank to the main one. If the total amount of gas is less than was requested, as much is given as there is left. The method returns the amount of gas given. - public String toString() returns a clear character string presentation of the gas station's status. (18 points) 3. Implement the following guessing game as an interactive program. Before the game starts the game leader inputs 100 integers into the program in random order. Then the player starts to use the program. The player tries to guess the numebers that the game leader has input in the computer. The game ends, when the player has guessed three different numbers. The result is the number of guesses, so it is at least three. You may assume that the game leader really inputs 100 different numbers. For the sake of efficiency, the search for guessed numbers must be programmed with the Binary Search (16 points) Sunny and Warm Summer!