forked from Labore/PR2-L
added code for exercises
parent
d555e9ae86
commit
2cc61992d1
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin",
|
||||
"java.project.referencedLibraries": [
|
||||
"lib/**/*.jar"
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
public class Datei {
|
||||
// Hier könnte ihr genialer Code stehen
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
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,5 @@
|
|||
public class IndexUI {
|
||||
public static void main(String[] args) throws Exception {
|
||||
// Hier könnte ihr genialer Code stehen
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin",
|
||||
"java.project.referencedLibraries": [
|
||||
"lib/**/*.jar"
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
/**Copyright (c) Louis, D., Müller, P.: "Java. Der umfassende Programmierkurs"
|
||||
* O`Reilly Verlag, Köln, 2014
|
||||
* StackDemo.java - Demoprogramm zu Container, S. xxx
|
||||
*/
|
||||
|
||||
class Item {
|
||||
// Konstruktor
|
||||
Item(char z, int w) {
|
||||
zeichen = z;
|
||||
prio = w;
|
||||
}
|
||||
|
||||
char zeichen;
|
||||
int prio;
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
/**Copyright (c) Louis, D., Müller, P.: "Java. Der umfassende Programmierkurs"
|
||||
* O`Reilly Verlag, Köln, 2014
|
||||
* StackDemo.java - Demoprogramm zu Container, S. xxx
|
||||
*/
|
||||
|
||||
import java.util.Scanner;
|
||||
import java.util.Stack;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class StackDemo {
|
||||
public static void main(String[] args) throws Exception {
|
||||
// Hier könnte ihr genialer Code stehen
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue