1 / 12

Introduktion til programmering

Introduktion til programmering. Repetition - ArrayList. dIntProg. Sidste forelæsning (11/ 10) sjove løsninger på Ants & Spiders ? præmieuddeling repetition (ønsker til repetition på webboard ) ”juleforelæsning” om marcipanbrød m.m. Afleveringsopgaver (adgang til eksamen)

chad
Télécharger la présentation

Introduktion til programmering

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduktion til programmering Repetition - ArrayList

  2. dIntProg • Sidste forelæsning (11/10) • sjove løsninger på Ants & Spiders ? • præmieuddeling • repetition (ønsker til repetition på webboard) • ”juleforelæsning” om marcipanbrød m.m. • Afleveringsopgaver (adgang til eksamen) • tilbagemelding til Studiekontoret (onsdag 17/10) • sidste frist aftales med jeres instruktor • check at jeres opfattelse stemmer overens med instruktorens

  3. Manual

  4. Realisering af en-til-mange publicclassB{ … } import java.util.*; publicclassA{ private ArrayList<B> bs; public Scope() { bs = new ArrayList<B>(); } public voidaddB(Bb) { bs.add(b); } } publicclassA{ public A() { } } import java.util.*; publicclassA{ private ArrayList<B> bs; public A() { bs = new ArrayList<B>(); } public voidaddB(Bb) { bs.add(b); } } * B A

  5. Realisering af en-til-mange (ImErKo) • For at realisere en en-til-mange relation i koden skal man : • Importere en collection (f.eks. en liste) import java.util.ArrayList; • Erklære en attribut af passende type private ArrayList<Person> persons; • Initialisere collection’en i Konstruktøren public AddressBook(){ persons = new ArrayList<Person>(); }

  6. Generisk klassemodel (A * B) * A B DNA-register * DNA DNA * AminoAcidResidue Picture * Pixel Animation * Picture World * Actor (Wombat, Crab, Lobster, ...) Playlist * Track Track * Picture ... Også skabelon for eksamensprojekter...

  7. Checkliste for Comparable<T> • Antagelse • vi har en liste med elementer af typen T:ArrayList<T> lst; • vi ønsker at kunne udføre standardoperationer der fordrer en naturlig ordning (f.eks. max(lst) og sort(lst) fra Collections) • Lad klassen T implementere Comparable<T>: public classT implementsComparable<T> { ... public intcompareTo(T t) { return ... } }

  8. Checkliste for Comparable<T>, fortsat • Det er underforstået at det er den naturlige ordning der anvendes ved kald af standard-operationer: ArrayList<T> lst; ... T res= Collections.max(lst); ... Collections.sort(lst);

  9. Eksamensprojekt 1 e08

  10. Eksamensprojekt f08

  11. Eksamensprojekt 2 e08

  12. Eksamensprojekt 4 e06

More Related