ITI0011:praktikum 6 T8

Allikas: Kursused
Redaktsioon seisuga 6. oktoober 2014, kell 21:45 kasutajalt Ago (arutelu | kaastöö) (Uus lehekülg: 'Tagasi ITI0011 lehele. == Üldine == Siin on praktikumi, mis toimub teisipäeval, 7. oktoobril kell 8, info. Praktikumis käsitletavad teemad: * veebist lugemine * Stringi...')
(erin) ←Vanem redaktsioon | Viimane redaktsiooni (erin) | Uuem redaktsioon→ (erin)
Mine navigeerimisribale Mine otsikasti

Tagasi ITI0011 lehele.

Üldine

Siin on praktikumi, mis toimub teisipäeval, 7. oktoobril kell 8, info.

Praktikumis käsitletavad teemad:

  • veebist lugemine
  • Stringi parsimine
  • objekti loomine
  • (sortimine)

Exercise

You have a database of sports activities. The database is stored in a text file. Now you want to write a program that reads the data from the file and converts it into Java objects. You will write different objects for different activities. But in order to store them in one collection, you need to have a common type (e.g. super class).

1) Create objects for different activities:

  • running. has fields:
    • date (when the activity took place)
    • distance (in kms)
    • duration (in minutes)
    • steps (how many steps were done)
    • maxSpeed (in km/h)
  • cycling. has fields:
    • date (when the activity took place)
    • distance (in kms)
    • duration (in minutes)
    • max speed (in km/h)
  • walking
    • date (when the activity took place)
    • distance (in kms)
    • duration (in minutes)
    • resting duration (how many minutes in total resting took place during the activity)

2) Read information from file.

The structure of the file:

in case of running:

date R distance duration steps maxspeed

in case of cycling:

date C distance duration maxspeed

in case of walking:

date W distance duration restduration

For example the file:

2014-10-01  R 10 50 5660 10
2014-10-03 C 12 30 33
2014-10-05 W 4 60 20

would yield in 3 objects: one running object, one cycling object and one walking object.

3) (optional) try to sort the objects by date.

An example: http://stackoverflow.com/questions/6510724/how-to-convert-java-string-to-date-object