wiki:k2014/demot/demo11english
Last modified 3 years ago Last modified on 2015-02-13 11:10:13

Demot » Demo 11, 30.3.2015

Task 1-2*. Currencies

Write textbased currency exhange program that has a constant array

 cur.   cour.
+-----+----------+
|mk   |  1.0     |
|$    |  5.7     |
|EUROA|  5.94573 |
|SKr  |  0.6     |
+-----+----------+ 

and the program looks like this:

Amount and currency>10 Skr[RET]
10.00 Skr is 6.00 mk.
Amount and currency>2 EUROA[RET]
2 EUROA is 11.89 mk.
Amount and currency>>end[RET]
Thank you!

You can create graphical version too, if you want to.

Task 3. Currencies from a file

Change the previous program so that the currency array is read from a file.

Task 4. List all

In the example ListaaKaikki.java the program prints out all the names of files in a folder. Change the example so that it instead prints all the subfolders in the folder too.

Task 5. Call hierarchy

The call hierarchy in the example project for step5.1 method "Lisää jäsen" in KerhoGui looks like this (if system libraries are not shown):

KerhoGui - klikataan Uusi jäsen
  KerhoGui.ActionUusiJasen.actionPerformed
    KerhoSwing.uusiJasen()
      Jasen() - parametriton konstruktori
      Jasen.rekisteroi()
      Jasen.vastaaAkuAnkka()
         HetuTarkistus.arvohetu()
         Jasen.vastaaAkuAnkka(hetu)
      Kerho.lisaa(jasen)
         Jasenet.lisaa(jasen)
      KerhoSwing.hae(nro)
         ComboBoxChooser.getSelectedIndex()
         KerhoSwing.setVirhe()
         ListBoxChooser.clear()
         Kerho.getJasenia()
            Jasenet.getLkm()
         Kerho.annaJasen(i)
            Jasenet.anna(i)
         Jasen.getTunnusNro()
         ListBoxChooser.add(nimi,jasen)
         ListBoxChooser.setSelectedIndex(index)

Write the same kind of call hierarchy for one of your methods that works the same way as "Lisää jäsen" does.

Task 6*. Minimum of a function

Write function funMin that will be taken a function-object as a parameter and the range of x. Function will return the minimum of the given mathematical function. You can look at the example function Integroi2.java.

Task 7&8. Drawing Sin

Write a program that draws the function sin(x) in the following way: (make it automatically scale on y-axis, make it also easy to change the drawn function. For an example function, check Integroi2.java):

I will draw the function sin(x)
Give me range and density for drawing> (-5.00  5.00  0.50) [ret]
                                           *
                                           *
                                       *
                               *
                     *
            *
     *
    *
       *
              *
                       *
                                 *
                                        *
                                           *
                                          *
                                   *
                          *
                *
        *
    *
    *

Main program for task

  public static void main(String[] args)  {
    double x1=-5,x2=5,dx=0.5,y1,y2; String s;
    FunktioRR f = new SinFun();

    System.out.println("I will draw the function sin(x)");
    s = Syotto.kysy("Give me range and density for drawing",
                    Mjonot.fmt(x1,4,2) + " " + Mjonot.fmt(x2,4,2) + " "
                    +  Mjonot.fmt(dx,4,2));
    StringBuffer sb = new StringBuffer(s);
    x1 = Mjonot.erota(sb,' ',x1);
    x2 = Mjonot.erota(sb,' ',x2);
    dx = Mjonot.erota(sb,' ',dx);

    y1 = funMin(f,x1,x2,dx);
    y2 = funMax(f,x1,x2,dx);

    draw(f,x1,x2,y1,y2,dx);

  }

Syotto.kysy and Mjonot.erota are accessible in the Ali.jar package.