581258-1 Introduction to Programming: Mid-Term Exam 1 27.10.1998

Write the course name and the exam date along with your name, birthdate, and signature at the top of each of your answer sheets.

You may make use of the Lue or Read classes in your solutions.

  1. Describe accurately
                                                                  (6 points)
    

  2. Write a method readFromRange() that receives two int values as its parameters that specify the upper and lower bound for the desired input number. The method asks the user for a whole number within the upper and lower bounds and does not give up until the user enters a valid number; the method returns this number as its value. It must be possible to provide the parameters in either order.
                                                                  (5 points)
    

  3. Write an interactive (i.e., discursive) program that converts from Finnish markka (FIM) to some other currency (equation: result = rate * FIM).

    First, the program asks for the rate and the name of the foreign currency, after which it can be used to calculate several conversions from FIM to the foreign currency. The program checks the validity of its numerical input and complains on errors. The program must generate clear and understandable output. Design the way the program ends.

                                                                  (5 points)
    

  4. A soda pop factory produces its drink from three ingredients: water, coloring agent, and sugar. Each ingredient has its own tank. The secret ingredient for the soda pop is: 10 parts water, 0.5 parts coloring agent, and 3.5 parts sugar. This mixing ratio produces 14 liters of refreshing soda.

    Write the class AgriCola to implement the soda pop factory. The implementation of the ingredient tanks is kept hidden from the user of the AgriCola object; they can only be manipulated via methods. The user of an AgriCola object can produce soda pop by calling the method
    double produceJuice(int howMuch).

    Specify the structure of the factory precisely; its constructors and methods. Implement the AgriCola class.

    Also write a main program to test your class.

                                                               (6 pistettä)