My Collections

master
3009594 2024-09-23 14:25:11 +02:00
parent b84ed6ce96
commit 17d36e5204
19 changed files with 350 additions and 6 deletions

View File

@ -3,7 +3,7 @@ package BankSystemGUI;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Controller {
public class Controller {
private User user;
private Konto konto;
private Bank bank;
@ -20,6 +20,7 @@ public class Controller {
action_login();
action_Einzahlen();
Einzahlen();
}
public void login() {
@ -75,7 +76,4 @@ public class Controller {
}
});
}
}

View File

@ -1 +0,0 @@
,OBAI/obaya,obai,21.09.2024 22:26,file:///C:/Users/obaya/AppData/Roaming/LibreOffice/4;

View File

@ -0,0 +1,30 @@
package MyCollections.List;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class JTest {
My_ArrayList<Number> test;
@BeforeEach
void erstelle_objekt() {
test = new My_ArrayList<>();
}
@Test
void add_atIndex_test() {
assertTrue(test.add(2,2.2));
}
@Test
void add_test() {
assertTrue(test.add(12.2));
}
}

View File

@ -0,0 +1,26 @@
package MyCollections.List;
import MyCollections.MyCollection;
public interface MyList<V> extends MyCollection<V> {
boolean add(V e);
boolean add(int index, V element);
int get(int index);
boolean set(int index, V element);
boolean remove(Object o);
boolean remove(int index);
int size();
boolean isEmpty();
boolean contains(Object o);
int indexOf(Object o);
void printAll();
}

View File

@ -0,0 +1,102 @@
package MyCollections.List;
public class My_ArrayList <V> implements MyList<V> {
private int size;
private V[] arr;
private int index;
My_ArrayList(){
size = 10;
index = 0;
arr = (V[]) new Object[size];
}
@Override
public boolean add(V e) {
if (index >= arr.length)
erstell_neue_array();
arr[index] = e;
index++;
return true;
}
public void erstell_neue_array() {
size *= 2;
V[] neuarr = (V[]) new Object[size];
for (int i = 0; i < arr.length ; i++)
neuarr[i] = arr[i];
arr = neuarr;
}
@Override
public boolean add(int i, V element) {
if (arr[i] == null) {
arr[i] =element ;
return true;
}
return false;
}
@Override
public int get(int index) {
return 0;
}
@Override
public boolean set(int index, V element) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean remove(Object o) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean remove(int index) {
// TODO Auto-generated method stub
return false;
}
@Override
public int size() {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean contains(Object o) {
// TODO Auto-generated method stub
return false;
}
@Override
public int indexOf(Object o) {
// TODO Auto-generated method stub
return 0;
}
@Override
public void printAll() {
int i = 0;
System.out.print("[");
while(arr[i] != null && i < arr.length) {
System.out.println(arr[i] + " ");
i++;
}
System.out.print("]");
}
}

View File

@ -0,0 +1,20 @@
package MyCollections.List;
import java.util.ArrayList;
public class Test {
public static void main(String[] args) {
ArrayList<Integer> test = new ArrayList<>();
test.add(12);
test.add(13);
System.out.println(test);
test.add(0, 14);
System.out.println(test);
}
}

View File

@ -0,0 +1,53 @@
package MyCollections;
public class MyArrayList <v> {
private int size;
private v[] arr;
private int index;
MyArrayList(){
size = 10;
index = 0;
arr =(v[]) new Object[size];
}
public void add(v value) {
if (index >= arr.length)
erzeuge_neue_array();
arr[index] = value;
index++;
}
public void erzeuge_neue_array() {
size *=2;
v[] neuArray =(v[]) new Object[size];
for (int i = 0; i < arr.length; i++)
neuArray[i] = arr[i];
arr = neuArray;
}
public void printall() {
int i = 0;
while(arr[i] != null) {
System.out.print(arr[i] + " ");
i++;
}
}
public static void main(String[] args) {
MyArrayList<Integer> mylist = new MyArrayList<>();
for (int i = 1; i <= 30; i++)
mylist.add(i);
mylist.printall();
}
}

View File

@ -0,0 +1,25 @@
package MyCollections;
public interface MyCollection <V> {
boolean add(V e);
boolean add(int index, V element);
int get(int index);
boolean set(int index, V element);
boolean remove(Object o);
boolean remove(int index);
int size();
boolean isEmpty();
boolean contains(Object o);
int indexOf(Object o);
void printAll();
}

View File

@ -0,0 +1,18 @@
package MyGraphen;
import java.util.ArrayList;
public class Graph {
ArrayList<Knoten> knoten;
Graph(){
knoten = new ArrayList<>();
}
public void add_Knoten(Knoten knote) {
knoten.add(knote);
}
}

View File

@ -0,0 +1,20 @@
package MyGraphen;
public class Kanten {
Knoten knote1;
Knoten knote2;
Kanten(Knoten knote1, Knoten knote2){
this.knote1 = knote1;
this.knote2 = knote2;
this.knote1.add_Kante(this);
this.knote2.add_Kante(this);
}
public Knoten getpartner(Knoten knote) {
Knoten partner = (knote == knote1)? knote2 : knote1;
return partner;
}
}

View File

@ -0,0 +1,26 @@
package MyGraphen;
import java.util.ArrayList;
public class Knoten {
int value;
ArrayList<Kanten> kanten;
Knoten(int value){
this.value = value;
kanten = new ArrayList<>();
}
public void add_Kante(Kanten kante) {
this.kanten.add(kante);
}
public ArrayList<Knoten> get_partner() {
ArrayList<Knoten> alle_knoten = new ArrayList<>();
for (Kanten k : kanten)
alle_knoten.add(k.getpartner(this));
return alle_knoten;
}
}

View File

@ -0,0 +1,23 @@
package MyGraphen;
public class Main {
public static void main(String[] args) {
Graph graph = new Graph();
Knoten knote1 = new Knoten(1);
Knoten knote2 = new Knoten(2);
Kanten k1 = new Kanten(knote1,knote2);
Knoten knote3 = new Knoten(3);
Kanten k2 = new Kanten(knote1,knote3);
System.out.println(knote1.get_partner());
graph.add_Knoten(knote1);
graph.add_Knoten(knote2);
graph.add_Knoten(knote3);
System.out.println(graph.knoten);
}
}

View File

@ -1,8 +1,12 @@
package Teste;
import java.util.ArrayList;
public class kopieArray {
public static void main(String[] args) {
ArrayList<String> test;
// /*
// * das ein falsches Verfahren, um ein Array in einem anderen Array
// * zu koopieren, in dem Fall kopieArray ist ein RefrenzVariable, die auf das selbe Array zeigt