581258-1 Introduction to Programming: First course examination 12.3.1999 27.10.1998

Write the name and date of the course and your name, date of birth and signature on the top of each paper. You are allowed to use of the Read (or Lue) class in your solutions. You may also use "S.o.p" as shorthand for "System.out.prinln".

Questions 1 and 4 slightly differ from the Finnish version, because of using different text books.

  1. Answer shortly but precisely:
                                                         (6 points)
    

  2. MinMax is a gadget for registering maximum and minimum temperature values. Temperatures are input to the gadget and the user can at any time ask the highest and the lowest temperature that MinMax has received. At the beginning of its use, MinMax sets both the values to 0.0. Also later the gadget can be reset to have zero values. The user can ask, whether MinMax is at the beginning state or can she count on the temperature values.

    Implement the gadget as a class MinMax, that has a constructor and the following accessors:

                                                              (5 points)
    

  3. Write an interactive program that calculates speeds, when distance is given in kilometers and time is given in hours. The speed is calculated by formula: speed=distance/time. The program asks the data from the user, and checks the correctness of given data. The program can calculate several speeds on one run.
                                                              (5 points)
    

  4. [The names of materials - product and its components - are generalized for this English version.]
    A factory produces a product P by using 3 components: A, B and C. Six kilograms P is made by mixing 3 Kg A, 2 Kg B and 1 Kg C.

    Design a class ProduceP for an implementation of P-factory. There are at least methods for filling the component containers, and a parameterless method for producing P. The producing method produces every time as much P as possible; So every time at least one of the containers becomes empty. The value of the method is the amount of P produced.

    Program the class ProduceP. The design process needs not be described, but the program must be commented thoroughly, so that the structure and design desicions become clear to the reader.

    Explain shortly how you would test the class.

                                                           (5 points)