Erinevus lehekülje "ITI0011:praktikum 6 T8" redaktsioonide vahel
48. rida: | 48. rida: | ||
2) Read information from file: http://courses.cs.ttu.ee/w/images/7/76/Praktikum-06-input.txt | 2) Read information from file: http://courses.cs.ttu.ee/w/images/7/76/Praktikum-06-input.txt | ||
− | The structure of the file: | + | The structure of the file (R, C, W indicates activity type: running, cycling, walking accordingly): |
in case of running: | in case of running: |
Redaktsioon: 7. oktoober 2014, kell 04:57
Tagasi ITI0011 lehele.
Üldine
Siin on praktikumi, mis toimub teisipäeval, 7. oktoobril kell 8, info.
Praktikumis käsitletavad teemad:
- git
- veebist lugemine
- Stringi parsimine
- objekti loomine
- (sortimine)
Kood tuleb üles laadida git'i. Kausta (projekti) nimi peaks olema "prax6".
Tips
- URL, URL.openStream()
- BufferedReader
- String, String.split
- StringTokenizer, StringTokenizer.nextToken()
- Integer.parseInt(String), Double.parseDouble(String)
- Collections.sort(List, Comparator)
- Object.toString()
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: http://courses.cs.ttu.ee/w/images/7/76/Praktikum-06-input.txt
The structure of the file (R, C, W indicates activity type: running, cycling, walking accordingly):
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/2784514/sort-arraylist-of-custom-objects-by-property
4) print out activities.
Activities should be stored in a list or array (or something else similar). Print out all the information about the activity. In case of running, print out "running" + date, duration, maxspeed, steps, distance etc.