Linked List
parent
7052e9e82c
commit
e6ee4839b2
|
@ -1,14 +1,14 @@
|
|||
package BankSystemGUI;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class BankSystemTest {
|
||||
|
||||
@Test
|
||||
public void testEinzahlung() {
|
||||
BankSystem test = new BankSystem();
|
||||
double x = test.einzahlung(100);
|
||||
assertEquals(100, x, 0.001); // Hier wird überprüft, ob der Kontostand 100.0 ist
|
||||
}
|
||||
}
|
||||
package BankSystemGUI;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class BankSystemTest {
|
||||
|
||||
@Test
|
||||
public void testEinzahlung() {
|
||||
BankSystem test = new BankSystem();
|
||||
double x = test.einzahlung(100);
|
||||
assertEquals(100, x, 0.001); // Hier wird überprüft, ob der Kontostand 100.0 ist
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -1,42 +1,42 @@
|
|||
package GUIAnwendungen;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.Border;
|
||||
|
||||
// mit Jpanel kann man alle grafischen Bauelemente einsetzen
|
||||
public class Jpanel {
|
||||
|
||||
public static void main(String[] args) {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBackground(Color.red);
|
||||
// setze eine Grafisches Bauelement (int x, int y, int width, int height)
|
||||
panel.setBounds(100, 100, 10, 10);
|
||||
|
||||
|
||||
JFrame frame = new JFrame();
|
||||
|
||||
//stellt sicher, dass keine automatische Positionierung und Größenanpassung erhalten
|
||||
frame.setLayout(null);
|
||||
|
||||
// setSize(width, height)
|
||||
frame.setSize(750, 750);
|
||||
|
||||
// setzte einen Überschrift für mein Fenster
|
||||
frame.setTitle("Mein erstes Fenster");
|
||||
|
||||
//setVisible(boolean): gibt an, ob mein Fenster sichtbar ist oder nicht
|
||||
frame.setVisible(true);
|
||||
|
||||
frame.add(panel);
|
||||
|
||||
|
||||
}
|
||||
|
||||
package GUIAnwendungen;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.Border;
|
||||
|
||||
// mit Jpanel kann man alle grafischen Bauelemente einsetzen
|
||||
public class Jpanel {
|
||||
|
||||
public static void main(String[] args) {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBackground(Color.red);
|
||||
// setze eine Grafisches Bauelement (int x, int y, int width, int height)
|
||||
panel.setBounds(100, 100, 10, 10);
|
||||
|
||||
|
||||
JFrame frame = new JFrame();
|
||||
|
||||
//stellt sicher, dass keine automatische Positionierung und Größenanpassung erhalten
|
||||
frame.setLayout(null);
|
||||
|
||||
// setSize(width, height)
|
||||
frame.setSize(750, 750);
|
||||
|
||||
// setzte einen Überschrift für mein Fenster
|
||||
frame.setTitle("Mein erstes Fenster");
|
||||
|
||||
//setVisible(boolean): gibt an, ob mein Fenster sichtbar ist oder nicht
|
||||
frame.setVisible(true);
|
||||
|
||||
frame.add(panel);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package Linked_List;
|
||||
|
||||
public class ElementList {
|
||||
Node head;
|
||||
|
||||
// ADD Methoden
|
||||
public void addAtIndex(int value, int index) {
|
||||
// Erstelle eine neue Knote
|
||||
Node newNode = new Node();
|
||||
// setze drin einen Wert
|
||||
newNode.value = value;
|
||||
// falls meine Liste leer ist!
|
||||
if (head == null) {
|
||||
head = newNode;
|
||||
return;
|
||||
}
|
||||
|
||||
if (index == 0) {
|
||||
newNode.next = head;
|
||||
head = newNode;
|
||||
return;
|
||||
}
|
||||
|
||||
Node temp = head;
|
||||
for (int i = 0; i < index - 1 && temp.next != null ; i++)
|
||||
temp = temp.next;
|
||||
|
||||
newNode.next = temp.next;
|
||||
temp.next = newNode;
|
||||
}
|
||||
public void addLast(int value) {
|
||||
// Erstelle eine neue Knote
|
||||
Node newNode = new Node();
|
||||
// setze drin einen Wert
|
||||
newNode.value = value;
|
||||
// falls meine Liste leer ist!
|
||||
if (head == null) {
|
||||
head = newNode;
|
||||
return;
|
||||
}
|
||||
// falls nicht!
|
||||
Node temp = head;
|
||||
while (temp.next != null)
|
||||
temp = temp.next;
|
||||
|
||||
temp.next = newNode;
|
||||
}
|
||||
public void addFirst(int value) {
|
||||
// Erstelle eine neue Knote
|
||||
Node newNode = new Node();
|
||||
// setze drin einen Wert
|
||||
newNode.value = value;
|
||||
|
||||
if (head == null)
|
||||
head = newNode;
|
||||
|
||||
/*
|
||||
* newNode.next = null, aber ist jetzt nicht mehr null,
|
||||
* weil es jetzt gleich head;
|
||||
*/
|
||||
newNode.next = head;
|
||||
head = newNode;
|
||||
|
||||
}
|
||||
//---------------------------------------------------
|
||||
|
||||
|
||||
public void printList() {
|
||||
if (head == null)
|
||||
return;
|
||||
|
||||
Node temp =head;
|
||||
System.out.print("[");
|
||||
while(temp != null) {
|
||||
System.out.print(temp.value + " ");
|
||||
temp = temp.next;
|
||||
}
|
||||
System.out.print("]");
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package Linked_List;
|
||||
|
||||
public class Node {
|
||||
int value;
|
||||
Node next;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package Linked_List;
|
||||
|
||||
public class Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ElementList e1 = new ElementList();
|
||||
e1.addLast(1);
|
||||
e1.addLast(2);
|
||||
e1.addLast(3);
|
||||
e1.addLast(5);
|
||||
e1.addAtIndex(10,2);
|
||||
e1.printList();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue