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

581325-0 Introduction to Programming, examination 8.11.1999/AW

Write on the top of each paper the name of the course, the date of the exam, your name, your date of birth and your signature. Every question is worth of 15 points. 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 2 is different. Use separate papers for each answer!

  1. Coffee automata is a device that produces coffee beverage from water and roasted coffee. Model this device as class a CoffeeAutomata:

    • public CoffeeAutomata(String brand)
      constructs a CoffeeAutomata-object. The water tank is empty, the roasted coffee container contains 0 units. ("Brand" means the "name" or "quality" of coffee used.)
    • public double amountOfWater()
      returns the amount of water.
    • public int amountOfRoastedCoffee()
      returns the amount of units of roasted coffee.
    • public String whatBrand()
      returns the brand of the coffee.
    • public void addWater(double amount)
      fills the water tank with the parameter amount (litres).
    • public void addRoastedCoffee(int amount)
      adds the parameter amount of units of roasted coffee to the roasted coffee container (one unit of roasted coffee is needed for producing one portion of coffee beverage).
    • public boolean produceCupOfCoffee()
      "produces one cup of coffee", the amount of water lessens 0.02 litres, one unit of roasted coffee is used. The method returns true, if it was possible to make a cup of coffee.
    • public String toString()

  2. Explain thoroughly:
    • What important difference there is between passing an int as a parameter and a String as a parameter?
    • What does "overloading a method" mean?
    • What is the meaning of "object" in Java?

  3. In an elegant café they serve French and Italian coffee. Coffee is produced by using the CoffeeAutomata-objects described in question 1. Program an application for the staff (=workers) of the café.

    The user interface of your program has commands:

         command
            1        fill the water tank of French coffee
            2        fill the roasted coffee contaner of French coffee
            3        produce a cup of French coffee
            4        fill the water tank of Italian coffee
            5        fill the roasted coffee contaner of Italian coffee
            6        produce a cup of Italian coffee
            7        close the café
    

    You are allowed to answer this question even if you did not program the class CoffeeAutomata!

  4. Program methods (these methods are meant to be called from some main method):