master
parent
121b0acb7c
commit
a8229b1b4f
Binary file not shown.
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry excluding="Indexverwaltung/src/" kind="src" path=""/>
|
||||||
|
<classpathentry kind="src" path="Indexverwaltung/src"/>
|
||||||
|
<classpathentry kind="output" path="Indexverwaltung/bin"/>
|
||||||
|
</classpath>
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>Dateien</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
|
@ -0,0 +1,21 @@
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Console {
|
||||||
|
Scanner scan = new Scanner(System.in);
|
||||||
|
|
||||||
|
public String readString() {
|
||||||
|
String eingabeString = scan.nextLine();
|
||||||
|
return eingabeString;
|
||||||
|
}
|
||||||
|
public char [] readCharArray() {
|
||||||
|
String text = scan.nextLine();
|
||||||
|
return text.toCharArray();
|
||||||
|
}
|
||||||
|
public boolean readBoolean() {
|
||||||
|
return scan.nextBoolean();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
public class DemoConsole {
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
Console console = new Console();
|
||||||
|
System.out.println("Text eingeben: ");
|
||||||
|
String text = console.readString();
|
||||||
|
System.out.println("Gelesener Text: " + text);
|
||||||
|
|
||||||
|
System.out.println("Text eingeben: ");
|
||||||
|
char [] ca = console.readCharArray();
|
||||||
|
System.out.println("Gelesenes char-Feld: ");
|
||||||
|
for(char celement: ca)
|
||||||
|
System.out.print(celement);
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
System.out.println("Boolean eingeben: ");
|
||||||
|
boolean b = console.readBoolean();
|
||||||
|
System.out.println("Gelesener Wert: " + b);
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-19">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>Indexverwaltung</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
|
@ -0,0 +1,2 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding/<project>=UTF-8
|
|
@ -0,0 +1,14 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=19
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=19
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=19
|
|
@ -0,0 +1,11 @@
|
||||||
|
/.DS_Store
|
||||||
|
/.classpath
|
||||||
|
/.project
|
||||||
|
/Console.class
|
||||||
|
/Datei.class
|
||||||
|
/DemoConsole.class
|
||||||
|
/Index.class
|
||||||
|
/IndexUI.class
|
||||||
|
/Indexverwaltung/
|
||||||
|
/Zaehler.png
|
||||||
|
/ZaehlerUI.class
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
public class Datei {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
import java.util.*;
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
public class Index {
|
||||||
|
// Attribute
|
||||||
|
private final int MAX = 10;
|
||||||
|
private String dateiname = "Indexdatei.txt";
|
||||||
|
private int indextabelle[]; // 0 .. MAX-1
|
||||||
|
private RandomAccessFile eineIndexDatei;
|
||||||
|
|
||||||
|
// Konstruktor
|
||||||
|
public Index()
|
||||||
|
{
|
||||||
|
indextabelle = new int[MAX];
|
||||||
|
// Initialisierung der indextabelle
|
||||||
|
for(int i = 0; i < MAX; i++) indextabelle[i] = -1;
|
||||||
|
// Kein Datensatz zu Schluessel vorhanden
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methoden
|
||||||
|
public void erzeugeEintrag(int schluessel, int index) throws IOException
|
||||||
|
{
|
||||||
|
/** Speichert zu einen Schluessel den zugehoerigen
|
||||||
|
* Datensatz-Index in der indextabelle
|
||||||
|
*/
|
||||||
|
if(schluessel < MAX)
|
||||||
|
indextabelle[schluessel] = index;
|
||||||
|
// Aktualisieren der Indexdatei,
|
||||||
|
// d. h. Abspeichern der Datei
|
||||||
|
aktualisiereIndexDatei(schluessel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int gibIndexZuSchluessel(int schluessel)
|
||||||
|
{
|
||||||
|
// Gibt zu dem Schluessel den gefundenen
|
||||||
|
// Datensatz-Index zurueck
|
||||||
|
if(schluessel < MAX)
|
||||||
|
return indextabelle[schluessel];
|
||||||
|
// oder -1, wenn Schluessel zu gross ist
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ladeIndexDatei() throws IOException
|
||||||
|
{
|
||||||
|
/** Liest die Indextabelle vollstaendig aus einer Datei
|
||||||
|
* Dies geschieht nur beim Start des Programms
|
||||||
|
*/
|
||||||
|
eineIndexDatei = new RandomAccessFile(dateiname, "r");
|
||||||
|
int index;
|
||||||
|
for(int schluessel = 0; schluessel < MAX; schluessel++)
|
||||||
|
{
|
||||||
|
index = eineIndexDatei.readInt();
|
||||||
|
indextabelle[schluessel] = index;
|
||||||
|
}
|
||||||
|
eineIndexDatei.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void speichereIndexDatei() throws IOException
|
||||||
|
{
|
||||||
|
/** Speichert die Indextabelle vollstaendig in einer Datei
|
||||||
|
* Dies geschlieht beim beenden des Programs
|
||||||
|
*/
|
||||||
|
eineIndexDatei = new RandomAccessFile(dateiname, "rw");
|
||||||
|
for(int schluessel = 0; schluessel < MAX; schluessel++)
|
||||||
|
eineIndexDatei.writeInt(indextabelle[schluessel]);
|
||||||
|
eineIndexDatei.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void aktualisiereIndexDatei(int schluessel) throws IOException
|
||||||
|
{
|
||||||
|
/** Aktualisiert die indextabelle in der Indexdatei
|
||||||
|
* Dies geschliet beim Hinzufuegen eines neuen
|
||||||
|
* Indexes oder Aendern eines alten Indexes
|
||||||
|
*/
|
||||||
|
eineIndexDatei = new RandomAccessFile(dateiname, "rw");
|
||||||
|
// eine int-Zahl belegt 4 Bytes
|
||||||
|
eineIndexDatei.seek((long)(schluessel * 4));
|
||||||
|
eineIndexDatei.writeInt(indextabelle[schluessel]);
|
||||||
|
eineIndexDatei.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zum Testen
|
||||||
|
public void gibIndextabelleAus()
|
||||||
|
{
|
||||||
|
int schluessel = 0;
|
||||||
|
for(int element : indextabelle)
|
||||||
|
{
|
||||||
|
System.out.println(schluessel + " " + element);
|
||||||
|
schluessel++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
public class IndexUI {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 343 KiB |
|
@ -0,0 +1,49 @@
|
||||||
|
public class ZaehlerUI {
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
Zaehler einZaehler, klonZaehler = null;
|
||||||
|
|
||||||
|
Verbraucher einVerbraucher = new Verbraucher("Schulz");
|
||||||
|
einZaehler = new Zaehler("Elektro", einVerbraucher, 123);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
klonZaehler = einZaehler.clone();
|
||||||
|
}
|
||||||
|
catch(CloneNotSupportedException e)
|
||||||
|
{
|
||||||
|
System.out.println("Fehler");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Zählerstand =" + einZaehler.getZaehlerstand()
|
||||||
|
+ " gehört zu Verbraucher " + einZaehler.getMeinVerbraucher().getName());
|
||||||
|
|
||||||
|
System.out.println("Geklonter Zähler Zählerstand = " + klonZaehler.getZaehlerstand()
|
||||||
|
+ " gehört zu Verbraucher " + klonZaehler.getMeinVerbraucher().getName());
|
||||||
|
|
||||||
|
if(einZaehler.getMeinVerbraucher() == klonZaehler.getMeinVerbraucher())
|
||||||
|
System.out.println("Verbraucher identisch");
|
||||||
|
else
|
||||||
|
System.out.println("Verbraucher nicht identisch");
|
||||||
|
|
||||||
|
Unterzaehler nochEinZaehler = new Unterzaehler("Gas", einVerbraucher, 500);
|
||||||
|
|
||||||
|
System.out.println("Zählerstand = " + nochEinZaehler.getZaehlerstand()
|
||||||
|
+ " Unterzählerstand: " + nochEinZaehler.getUnterzaehlerstand()
|
||||||
|
+ " gehört zu Verbraucher " + nochEinZaehler.getMeinVerbraucher().getName());
|
||||||
|
|
||||||
|
Unterzaehler klonUnterzaehler = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
klonUnterzaehler = nochEinZaehler.clone();
|
||||||
|
}
|
||||||
|
catch(CloneNotSupportedException e)
|
||||||
|
{
|
||||||
|
System.out.println("Fehler");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Geklonter Unterzähler: Zählerstand = " + klonUnterzaehler.getZaehlerstand()
|
||||||
|
+ " Unterzählerstand: " + klonUnterzaehler.getUnterzaehlerstand()
|
||||||
|
+ " gehört zu Verbraucher " + klonUnterzaehler.getMeinVerbraucher().getName());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<projectDescription>
|
<projectDescription>
|
||||||
<name>übung2</name>
|
<name>Mein_git</name>
|
||||||
<comment></comment>
|
<comment></comment>
|
||||||
<projects>
|
<projects>
|
||||||
</projects>
|
</projects>
|
||||||
|
|
Loading…
Reference in New Issue