Labor – Array-Verwaltung mit Füllstand: Fahrstreckenliste

Erstelle eine Klasse SmartFloatContainer mit Methodensatz analog zum Theorie-Unterlagen-Beispiel SmartIntContainer (alle Werte-Handhabungsmethoden müssen von Int-Wert auf Float-Wert umgestellt werden). Siehe theorie/a310_arrays-verwalten.adoc#id_arr-hdlg-fuellstand.

Diese Klasse soll dann als "intelligentes Array" als Basis einer Fahrstrecken-Liste (in km) verwendet werden, umgesetzt als Klasse FahrstreckenListe:

SmartFloatContainerBAD_VAL: float = Float.MIN_VALUEvalues: float[];freeIdx: int;Konstruktor(capacity: int)Konstruktor( theArray: float[], freeIdx: int)Konstruktor()usedCells(): intfreeCells(): intisFull(): booleangetCell(int idx): floatprintArray(int cols)Info- und Zugriffs-MethodenfillWithRandom(newFreeIdx: int, replace: boolean, minVal: float, maxVal: float): booleanopenGap(int idx) // schiebt gültige Werte ab 'idx' um 1 höher im ArraycloseGap(int idx) // füllt Lücke in Zelle 'idx' durch nachrückenHilfsmethodenappend(float value): booleanappend2(float value): booleaninsertAsFirst(float value): booleaninsert(int idx, float value): booleanreplace(int idx, float value): booleanremove(int idx): booleanremoveLast(): booleanremoveFirst(): booleanContainer-Änderungs-OperationenFahrstreckenListefahrstreckenListe: SmartFloatContainerKonstruktor()Konstruktor(kapazitaet: int)add(fahrstrecke : float): booleanremove(idx: int): boolean // false wenn idx ungültig//... siehe Beispiel in Theorie-UnterlagenDatenerfassungsize(): intminWert(): floatmaxWert(): floatmittelWert(): floatAuswertungenprintMesswerte(spalten: int)Ausgabe

Klasse FahrstreckenListe nutzt einen SmartFloatContainer namens fahrstreckenListe als Werte-Speicher.

  • Der Standard-Konstruktor nutzt die Standard-Kapazität des SmartFloatContainer (dessen Default-Konstruktor).

  • add(…​) …​ nutzt Methode append(…​) oder append2(…​) des SmartFloatContainer.

  • remove(…​) …​ analog

  • size() …​ Füllstand/Anzahl gültiger Elemente

  • minWert() …​ Kleinster gültiger Wert im Array/in SmartFloatContainer

  • maxWert() …​ Größter gültiger Wert im Array/in SmartFloatContainer

  • mittelWert() …​ Mittelwert der gültigen Zellen im Array/in SmartFloatContainer

Die Funktion der Klasse SmartFloatContainer ist mittels einer TESTKLASSE gründlich zu testen!