University of Helsinki / Dep. of Computer Science / Introduction to Programming / Copyright © 2000 Arto Wikla.

581325-0 Introduction to Programming, examination 13.11.2000/AW

Write the name of the course, the date of the exam, your name, personal number and signature on each paper.

Write each answer on a separate paper!

You are allowed to use the tools of the Lue-class (or Read-class) for reading the input. This examination is not a direct translation of the Finnish version: question 3 is slightly different.

  1. Give short and concise answers to the following:
                                                                (12 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 initial state, or if he can rely on the temperature values.

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

                                                                (12 points)
    

  3. Explain thoroughly the parameters. What important differences are there between passing int-values as parameters, String objects as parameters, and a SimpleStorage objects as parameters? Give good examples.
                                                                (12 points)
    

  4. In political elections one system of calculating the winners is based on proportional representation. In the proportional representation the candidates' so-called comparison figures (double) are computed in the following way.

    Model a candidate with the class Candidate, with at least the attributes name (String, non-empty), coalition (int, 1-10), and number of votes (int, 0-). The attributes are implemented as fields in the class public.

    Create a program with the help of class Candidate that asks for the data (name, coalition, number of votes) of 903 candidates and checks the accuracy of the data. Then the program computes the comparison figures of the candidates.

    Finally, the program outputs the 85 delegates and their 85 substitutes, along with their data, in the order of their comparison figures. Thus, the comparison figures decide who is elected, and in a tie, lots are drawn.

    For drawing lots, the following practice may be used.

      if (Math.random() < 0.5) 
         // first option
      else 
         // second option
    
                                                                (14 points)