Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 202f13d2bf | |||
| 1eb50ea3be | |||
| c3166986a3 | |||
| 7a2d7641d4 | |||
| 05ab636670 | |||
| db8ee0c3e6 | |||
| 96f3689792 | |||
| b475ca846b | |||
| aaed0d8af7 | |||
| 83041b4bf1 | |||
| dbb7c99ae3 | |||
| 39bc86e798 | |||
| f01bd8e7c3 | |||
| a3aa3af70b | |||
| 9c4877edee | |||
| ed73c8e876 | |||
| 47f9285f37 | |||
| 46b0410bc5 | |||
| adb6322144 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -3,6 +3,7 @@ target/
|
|||||||
!**/src/main/**/target/
|
!**/src/main/**/target/
|
||||||
!**/src/test/**/target/
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
### IntelliJ IDEA ###
|
||||||
.idea/modules.xml
|
.idea/modules.xml
|
||||||
.idea/jarRepositories.xml
|
.idea/jarRepositories.xml
|
||||||
@@ -36,3 +37,6 @@ build/
|
|||||||
|
|
||||||
### Mac OS ###
|
### Mac OS ###
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
### Accountdata ###
|
||||||
|
/accountdata
|
||||||
28
pom.xml
28
pom.xml
@@ -2,7 +2,7 @@
|
|||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<artifactId>P4</artifactId>
|
<artifactId>P5</artifactId>
|
||||||
<groupId>de.fh_aachen.oos</groupId>
|
<groupId>de.fh_aachen.oos</groupId>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
@@ -12,12 +12,6 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<configuration>
|
|
||||||
<compilerArgs>
|
|
||||||
<arg>--release</arg>
|
|
||||||
<arg>17</arg>
|
|
||||||
</compilerArgs>
|
|
||||||
</configuration>
|
|
||||||
<version>3.13.0</version>
|
<version>3.13.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
@@ -25,6 +19,14 @@
|
|||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<version>3.2.5</version>
|
<version>3.2.5</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>javafx-maven-plugin</artifactId>
|
||||||
|
<groupId>org.openjfx</groupId>
|
||||||
|
<version>${javafx.maven.plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<mainClass>ui.main</mainClass>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
@@ -39,6 +41,16 @@
|
|||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
<version>2.11.0</version>
|
<version>2.11.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<artifactId>javafx-controls</artifactId>
|
||||||
|
<groupId>org.openjfx</groupId>
|
||||||
|
<version>${javafx.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<artifactId>javafx-fxml</artifactId>
|
||||||
|
<groupId>org.openjfx</groupId>
|
||||||
|
<version>${javafx.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
@@ -55,6 +67,8 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.release>17</maven.compiler.release>
|
<maven.compiler.release>17</maven.compiler.release>
|
||||||
|
<javafx.version>22</javafx.version>
|
||||||
|
<javafx.maven.plugin.version>0.0.8</javafx.maven.plugin.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
@@ -1,315 +1,7 @@
|
|||||||
import bank.*;
|
|
||||||
import bank.exceptions.*;
|
import bank.exceptions.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
private static void testingTransactions(Payment p1, Payment p2, Transfer t1, Transfer t2) throws TransactionAttributeException {
|
|
||||||
System.out.println("Basic Testcases------------------");
|
|
||||||
|
|
||||||
Payment p1c = new Payment(p1);
|
|
||||||
Payment p2c = new Payment(p2);
|
|
||||||
|
|
||||||
System.out.print(p1);
|
|
||||||
System.out.print(p2);
|
|
||||||
System.out.print(p1c);
|
|
||||||
System.out.print(p2c);
|
|
||||||
|
|
||||||
Transfer t1c = new Transfer(t1);
|
|
||||||
Transfer t2c = new Transfer(t2);
|
|
||||||
|
|
||||||
System.out.print(t1);
|
|
||||||
System.out.print(t2);
|
|
||||||
System.out.print(t1c);
|
|
||||||
System.out.print(t2c);
|
|
||||||
|
|
||||||
System.out.println("\nTest Edgecases-----------------");
|
|
||||||
|
|
||||||
setInterestRateCatch(p2, -0.5);
|
|
||||||
setInterestRateCatch(p2, 1.5);
|
|
||||||
|
|
||||||
setAmountCatch(t1, -5);
|
|
||||||
|
|
||||||
System.out.println("\nCompare Payments--------------");
|
|
||||||
System.out.println(p1.equals(p1c));
|
|
||||||
System.out.println(p1.equals(p2));
|
|
||||||
|
|
||||||
System.out.println(p1.equals(new ArrayList<>()));
|
|
||||||
System.out.println(p1.equals(null));
|
|
||||||
|
|
||||||
System.out.println("\nCompare Transfers-------------");
|
|
||||||
System.out.println(t1.equals(t1c));
|
|
||||||
System.out.println(t1.equals(t2));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void testingBankWithTransactions(Transaction t1, Transaction t2, Transaction t3, Transaction t4, PrivateBank bank, String person) {
|
|
||||||
// ------------------------ Bank: Adding Payments
|
|
||||||
|
|
||||||
if(t1 instanceof Payment){
|
|
||||||
System.out.println("\n------------------------ Bank: Adding Payment");
|
|
||||||
System.out.println("p1 IncIntr. before adding : 0.0 = " + ((Payment) t1).getIncomingInterest());
|
|
||||||
System.out.println("p1 OutIntr. before adding : 0.0 = " + ((Payment) t1).getOutgoingInterest());
|
|
||||||
System.out.println("p2 IncIntr. before adding : 0.0 = " + ((Payment) t2).getIncomingInterest());
|
|
||||||
System.out.println("p2 OutIntr. before adding : 0.0 = " + ((Payment) t2).getOutgoingInterest());
|
|
||||||
System.out.println("p3 IncIntr. before adding : 0.5 = " + ((Payment) t3).getIncomingInterest());
|
|
||||||
System.out.println("p3 OutIntr. before adding : 0.0 = " + ((Payment) t3).getOutgoingInterest());
|
|
||||||
System.out.println("p4 IncIntr. before adding : 0.0 = " + ((Payment) t4).getIncomingInterest());
|
|
||||||
System.out.println("p4 OutIntr. before adding : 0.25= " + ((Payment) t4).getOutgoingInterest());
|
|
||||||
}
|
|
||||||
else if(t1 instanceof IncomingTransfer){
|
|
||||||
System.out.println("\n------------------------ Bank: Adding IncomingTransfer");
|
|
||||||
System.out.println("t1 Sender before adding : = " + ((IncomingTransfer) t1).getSender());
|
|
||||||
System.out.println("t1 Recipient before adding : = " + ((IncomingTransfer) t1).getRecipient());
|
|
||||||
System.out.println("t2 Sender before adding : Mustermann = " + ((IncomingTransfer) t2).getSender());
|
|
||||||
System.out.println("t2 Recipient before adding : Musterfrau = " + ((IncomingTransfer) t2).getRecipient());
|
|
||||||
System.out.println("t3 Sender before adding : Max Mustermann = " + ((IncomingTransfer) t3).getSender());
|
|
||||||
System.out.println("t3 Recipient before adding : Maria Musterfrau = " + ((IncomingTransfer) t3).getRecipient());
|
|
||||||
System.out.println("t4 Sender before adding : Maria Musterfrau = " + ((IncomingTransfer) t4).getSender());
|
|
||||||
System.out.println("t4 Recipient before adding : Max Musterman = " + ((IncomingTransfer) t4).getRecipient());
|
|
||||||
}
|
|
||||||
else if(t1 instanceof OutgoingTransfer){
|
|
||||||
System.out.println("\n------------------------ Bank: Adding OutgoingTransfer");
|
|
||||||
System.out.println("t1 Sender before adding : = " + ((OutgoingTransfer) t1).getSender());
|
|
||||||
System.out.println("t1 Recipient before adding : = " + ((OutgoingTransfer) t1).getRecipient());
|
|
||||||
System.out.println("t2 Sender before adding : Mustermann = " + ((OutgoingTransfer) t2).getSender());
|
|
||||||
System.out.println("t2 Recipient before adding : Musterfrau = " + ((OutgoingTransfer) t2).getRecipient());
|
|
||||||
System.out.println("t3 Sender before adding : Max Mustermann = " + ((OutgoingTransfer) t3).getSender());
|
|
||||||
System.out.println("t3 Recipient before adding : Maria Musterfrau = " + ((OutgoingTransfer) t3).getRecipient());
|
|
||||||
System.out.println("t4 Sender before adding : Maria Musterfrau = " + ((OutgoingTransfer) t4).getSender());
|
|
||||||
System.out.println("t4 Recipient before adding : Max Musterman = " + ((OutgoingTransfer) t4).getRecipient());
|
|
||||||
}
|
|
||||||
|
|
||||||
addingTransactionCatch(bank, person, t1);
|
|
||||||
addingTransactionCatch(bank, person, t1);
|
|
||||||
addingTransactionCatch(bank, person, t2);
|
|
||||||
addingTransactionCatch(bank, person, t3);
|
|
||||||
addingTransactionCatch(bank, person, t4);
|
|
||||||
|
|
||||||
System.out.println("\n------------------------ Bank: Printing Transactions");
|
|
||||||
List<Transaction> p = bank.getTransactions(person);
|
|
||||||
p.forEach(System.out::println);
|
|
||||||
|
|
||||||
System.out.println("\n------------------------ Bank: Printing Balance");
|
|
||||||
double balanceP1 = bank.getAccountBalance(person);
|
|
||||||
System.out.println("balance of Person1 " + person + " = " + balanceP1);
|
|
||||||
System.out.println("Payment = -15; Outgoing = -12.5; Incoming = 5");
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println("\n------------------------ Bank: Removing Transaction");
|
|
||||||
|
|
||||||
removingTransactionCatch(bank, person, t1);
|
|
||||||
removingTransactionCatch(bank, person, t1);
|
|
||||||
removingTransactionCatch(bank, person, t2);
|
|
||||||
removingTransactionCatch(bank, person, t3);
|
|
||||||
removingTransactionCatch(bank, person, t4);
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println("\n------------------------ Bank: Printing Transactions");
|
|
||||||
p = bank.getTransactions(person);
|
|
||||||
p.forEach(System.out::println);
|
|
||||||
|
|
||||||
System.out.println("\n------------------------ Bank: Printing Balance");
|
|
||||||
balanceP1 = bank.getAccountBalance(person);
|
|
||||||
System.out.println("balance of Person1 " + person + " 0 = " + balanceP1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
private static void testingBankWithListOfTransactions(List transactions, PrivateBank bank, String person) {
|
|
||||||
// ------------------------ Bank: Adding Payments
|
|
||||||
|
|
||||||
if(transactions.getFirst() instanceof Payment){
|
|
||||||
System.out.println("\n------------------------ Bank: Adding Payment");
|
|
||||||
System.out.println("p1 IncIntr. before adding : 0.0 = " + ((Payment) transactions.get(0)).getIncomingInterest());
|
|
||||||
System.out.println("p1 OutIntr. before adding : 0.0 = " + ((Payment) transactions.get(0)).getOutgoingInterest());
|
|
||||||
System.out.println("p2 IncIntr. before adding : 0.0 = " + ((Payment) transactions.get(1)).getIncomingInterest());
|
|
||||||
System.out.println("p2 OutIntr. before adding : 0.0 = " + ((Payment) transactions.get(1)).getOutgoingInterest());
|
|
||||||
System.out.println("p3 IncIntr. before adding : 0.5 = " + ((Payment) transactions.get(2)).getIncomingInterest());
|
|
||||||
System.out.println("p3 OutIntr. before adding : 0.0 = " + ((Payment) transactions.get(2)).getOutgoingInterest());
|
|
||||||
System.out.println("p4 IncIntr. before adding : 0.0 = " + ((Payment) transactions.get(3)).getIncomingInterest());
|
|
||||||
System.out.println("p4 OutIntr. before adding : 0.25= " + ((Payment) transactions.get(3)).getOutgoingInterest());
|
|
||||||
}
|
|
||||||
else if(transactions.getFirst() instanceof IncomingTransfer){
|
|
||||||
System.out.println("\n------------------------ Bank: Adding IncomingTransfer");
|
|
||||||
System.out.println("t1 Sender before adding : = " + ((IncomingTransfer) transactions.get(0)).getSender());
|
|
||||||
System.out.println("t1 Recipient before adding : = " + ((IncomingTransfer) transactions.get(0)).getRecipient());
|
|
||||||
System.out.println("t2 Sender before adding : Mustermann = " + ((IncomingTransfer) transactions.get(1)).getSender());
|
|
||||||
System.out.println("t2 Recipient before adding : Musterfrau = " + ((IncomingTransfer) transactions.get(1)).getRecipient());
|
|
||||||
System.out.println("t3 Sender before adding : Max Mustermann = " + ((IncomingTransfer) transactions.get(2)).getSender());
|
|
||||||
System.out.println("t3 Recipient before adding : Maria Musterfrau = " + ((IncomingTransfer) transactions.get(2)).getRecipient());
|
|
||||||
System.out.println("t4 Sender before adding : Maria Musterfrau = " + ((IncomingTransfer) transactions.get(3)).getSender());
|
|
||||||
System.out.println("t4 Recipient before adding : Max Musterman = " + ((IncomingTransfer) transactions.get(3)).getRecipient());
|
|
||||||
}
|
|
||||||
else if(transactions.getFirst() instanceof OutgoingTransfer){
|
|
||||||
System.out.println("\n------------------------ Bank: Adding OutgoingTransfer");
|
|
||||||
System.out.println("t1 Sender before adding : = " + ((OutgoingTransfer) transactions.get(0)).getSender());
|
|
||||||
System.out.println("t1 Recipient before adding : = " + ((OutgoingTransfer) transactions.get(0)).getRecipient());
|
|
||||||
System.out.println("t2 Sender before adding : Mustermann = " + ((OutgoingTransfer) transactions.get(1)).getSender());
|
|
||||||
System.out.println("t2 Recipient before adding : Musterfrau = " + ((OutgoingTransfer) transactions.get(1)).getRecipient());
|
|
||||||
System.out.println("t3 Sender before adding : Max Mustermann = " + ((OutgoingTransfer) transactions.get(2)).getSender());
|
|
||||||
System.out.println("t3 Recipient before adding : Maria Musterfrau = " + ((OutgoingTransfer) transactions.get(2)).getRecipient());
|
|
||||||
System.out.println("t4 Sender before adding : Maria Musterfrau = " + ((OutgoingTransfer) transactions.get(3)).getSender());
|
|
||||||
System.out.println("t4 Recipient before adding : Max Musterman = " + ((OutgoingTransfer) transactions.get(3)).getRecipient());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
addingTransactionCatch(bank, person, t1);
|
|
||||||
addingTransactionCatch(bank, person, t1);
|
|
||||||
addingTransactionCatch(bank, person, t2);
|
|
||||||
addingTransactionCatch(bank, person, t3);
|
|
||||||
addingTransactionCatch(bank, person, t4);
|
|
||||||
|
|
||||||
System.out.println("\n------------------------ Bank: Printing Transactions");
|
|
||||||
List<Transaction> p = bank.getTransactions(person);
|
|
||||||
p.forEach(System.out::println);
|
|
||||||
|
|
||||||
System.out.println("\n------------------------ Bank: Printing Balance");
|
|
||||||
double balanceP1 = bank.getAccountBalance(person);
|
|
||||||
System.out.println("balance of Person1 " + person + " = " + balanceP1);
|
|
||||||
System.out.println("Payment = -15; Outgoing = -12.5; Incoming = 5");
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println("\n------------------------ Bank: Removing Transaction");
|
|
||||||
|
|
||||||
removingTransactionCatch(bank, person, t1);
|
|
||||||
removingTransactionCatch(bank, person, t1);
|
|
||||||
removingTransactionCatch(bank, person, t2);
|
|
||||||
removingTransactionCatch(bank, person, t3);
|
|
||||||
removingTransactionCatch(bank, person, t4);
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println("\n------------------------ Bank: Printing Transactions");
|
|
||||||
p = bank.getTransactions(person);
|
|
||||||
p.forEach(System.out::println);
|
|
||||||
|
|
||||||
System.out.println("\n------------------------ Bank: Printing Balance");
|
|
||||||
balanceP1 = bank.getAccountBalance(person);
|
|
||||||
System.out.println("balance of Person1 " + person + " 0 = " + balanceP1);
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
// ------------------------ Catch-Helper ------------------------
|
|
||||||
|
|
||||||
private static void accountCreationCatch(Bank bank, String account){
|
|
||||||
try {
|
|
||||||
bank.createAccount(account);
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void accountCreationWihtListCatch(Bank bank, String account, List<Transaction> transactions){
|
|
||||||
try {
|
|
||||||
bank.createAccount(account, transactions);
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setInterestRateCatch(Payment p, double interestrate) {
|
|
||||||
try {
|
|
||||||
p.setIncomingInterest(interestrate);
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println(e);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
p.setOutgoingInterest(interestrate);
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setAmountCatch(Transaction t, double amount) {
|
|
||||||
try {
|
|
||||||
t.setAmount(amount);
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void addingTransactionCatch(Bank bank, String person, Transaction transaction) {
|
|
||||||
try {
|
|
||||||
bank.addTransaction(person, transaction);
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static void removingTransactionCatch(Bank bank, String person, Transaction transaction) {
|
|
||||||
try {
|
|
||||||
bank.removeTransaction(person, transaction);
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ------------------------ MAIN ------------------------
|
|
||||||
|
|
||||||
public static void main(String[] args) throws TransactionAttributeException, IOException, java.io.IOException, TransactionAlreadyExistException, AccountAlreadyExistsException, AccountDoesNotExistException {
|
public static void main(String[] args) throws TransactionAttributeException, IOException, java.io.IOException, TransactionAlreadyExistException, AccountAlreadyExistsException, AccountDoesNotExistException {
|
||||||
String person1 = "Max Mustermann";
|
|
||||||
String person2 = "Maria Musterfrau";
|
|
||||||
String person3 = "Tom Mustermann";
|
|
||||||
String person4 = "Hannah Musterfrau";
|
|
||||||
|
|
||||||
// ------------------------ Transactions ------------------------
|
|
||||||
|
|
||||||
|
|
||||||
Payment p1 = new Payment("01.01.24", 10, "Verwendungszweck P1");
|
|
||||||
/*
|
|
||||||
Payment p2 = new Payment("01.01.24", 10, "Verwendungszweck P2", 0, 0);
|
|
||||||
Payment p3 = new Payment("01.01.24", -10, "Verwendungszweck P3", 0.5, 0);
|
|
||||||
Payment p4 = new Payment("01.01.24", -10, "Verwendungszweck P4", 0, 0.25);
|
|
||||||
|
|
||||||
Transfer t1 = new Transfer("01.01.24", 10, "Verwendungszweck T1");
|
|
||||||
Transfer t2 = new Transfer("01.01.24", 10, "Verwendungszweck T2", "Mustermann", "Musterfrau");
|
|
||||||
Transfer t3 = new Transfer("01.01.24", 10, "Verwendungszweck T3", person1, person2);
|
|
||||||
Transfer t4 = new Transfer("01.01.24", 10, "Verwendungszweck T4", person2, person1);
|
|
||||||
Transfer t5 = new Transfer("01.01.24", 15, "Verwendungszweck T5", person2, person3);
|
|
||||||
Transfer t6 = new Transfer("01.01.24", 20, "Verwendungszweck T6", person2, person4);
|
|
||||||
|
|
||||||
|
|
||||||
IncomingTransfer it1 = new IncomingTransfer(t1.getDate(), t1.getAmount(), t1.getDescription());
|
|
||||||
IncomingTransfer it2 = new IncomingTransfer(t2.getDate(), t2.getAmount(), t2.getDescription(), person2, person1);
|
|
||||||
IncomingTransfer it3 = new IncomingTransfer(t3.getDate(), t3.getAmount(), t3.getDescription(), person3, person1);
|
|
||||||
IncomingTransfer it4 = new IncomingTransfer(t4.getDate(), t4.getAmount(), t4.getDescription(), person4, person1);
|
|
||||||
IncomingTransfer it5 = new IncomingTransfer(t5.getDate(), t5.getAmount(), t5.getDescription(), person4, person1);
|
|
||||||
IncomingTransfer it6 = new IncomingTransfer(t6.getDate(), t6.getAmount(), t6.getDescription(), person3, person1);
|
|
||||||
|
|
||||||
OutgoingTransfer ot1 = new OutgoingTransfer(t1.getDate(), t1.getAmount(), t1.getDescription());
|
|
||||||
OutgoingTransfer ot2 = new OutgoingTransfer(t2.getDate(), t2.getAmount(), t2.getDescription(), person2, person1);
|
|
||||||
OutgoingTransfer ot3 = new OutgoingTransfer(t3.getDate(), t3.getAmount(), t3.getDescription(), person2, person1);
|
|
||||||
OutgoingTransfer ot4 = new OutgoingTransfer(t4.getDate(), t4.getAmount(), t4.getDescription(), person2, person3);
|
|
||||||
OutgoingTransfer ot5 = new OutgoingTransfer(t5.getDate(), t5.getAmount(), t5.getDescription(), person2, person3);
|
|
||||||
OutgoingTransfer ot6 = new OutgoingTransfer(t6.getDate(), t6.getAmount(), t6.getDescription(), person2, person4);
|
|
||||||
|
|
||||||
List<Transaction> paymentsList = new ArrayList<>(Arrays.asList(p1, p2, p3, p4));
|
|
||||||
List<Transaction> incomingTransfersList = new ArrayList<>(Arrays.asList(it2, it3, it4, it5, it6));
|
|
||||||
List<Transaction> outgoingTransferList = new ArrayList<>(Arrays.asList(ot2, ot3, ot4, ot5, ot6));
|
|
||||||
List<Transaction> incomingTransfersListWrong = new ArrayList<>(Arrays.asList(it1, it2, it3, it4, it5, it6));
|
|
||||||
List<Transaction> outgoingTransferListWrong = new ArrayList<>(Arrays.asList(ot1, ot2, ot3, ot4, ot5, ot6));
|
|
||||||
|
|
||||||
testingTransactions(p1, p2, t1, t2);
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
// ------------------------ Bank ------------------------
|
|
||||||
|
|
||||||
System.out.println("\n------------------------ Bank");
|
|
||||||
PrivateBank bank = new PrivateBank("Sparkasse", 0.5, 0.25,"accountdata");
|
|
||||||
PrivateBank bank1 = new PrivateBank("Commerzbank", 0.5, 0.25,"accountdata");
|
|
||||||
|
|
||||||
// ------------------------ Bank: Adding Accounts
|
|
||||||
|
|
||||||
bank.readAccounts();
|
|
||||||
bank.writeAccount("Max");
|
|
||||||
bank.addTransaction("Max",p1);
|
|
||||||
bank.writeAccount("Max");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -97,4 +97,19 @@ public interface Bank {
|
|||||||
* @return the list of all transactions by type
|
* @return the list of all transactions by type
|
||||||
*/
|
*/
|
||||||
List<Transaction> getTransactionsByType(String account, boolean positive);
|
List<Transaction> getTransactionsByType(String account, boolean positive);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delets an existing account
|
||||||
|
* @param account the account to be deleted
|
||||||
|
* @throws AccountDoesNotExistException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
void deleteAccount(String account) throws AccountDoesNotExistException, IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of all account names
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<String> getAllAccounts();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ public class PrivateBank implements Bank, JsonSerializer<Transaction>, JsonDeser
|
|||||||
|
|
||||||
// 2 setting as incoming transfer
|
// 2 setting as incoming transfer
|
||||||
else if (transaction instanceof IncomingTransfer) {
|
else if (transaction instanceof IncomingTransfer) {
|
||||||
if (((IncomingTransfer) transaction).getSender().equals("") || ((IncomingTransfer) transaction).getRecipient().equals(""))
|
if (((IncomingTransfer) transaction).getSender().isEmpty() || ((IncomingTransfer) transaction).getRecipient().isEmpty())
|
||||||
throw new TransactionAttributeException("Transfer without sender or recipient");
|
throw new TransactionAttributeException("Transfer without sender or recipient");
|
||||||
|
|
||||||
else if (((IncomingTransfer) transaction).getRecipient().equals(account))
|
else if (((IncomingTransfer) transaction).getRecipient().equals(account))
|
||||||
@@ -232,7 +232,7 @@ public class PrivateBank implements Bank, JsonSerializer<Transaction>, JsonDeser
|
|||||||
|
|
||||||
// 3 setting as outgoing transfer
|
// 3 setting as outgoing transfer
|
||||||
else if (transaction instanceof OutgoingTransfer) {
|
else if (transaction instanceof OutgoingTransfer) {
|
||||||
if (((OutgoingTransfer) transaction).getSender().equals("") || ((OutgoingTransfer) transaction).getRecipient().equals(""))
|
if (((OutgoingTransfer) transaction).getSender().isEmpty() || ((OutgoingTransfer) transaction).getRecipient().isEmpty())
|
||||||
throw new TransactionAttributeException("Transfer without sender or recipient");
|
throw new TransactionAttributeException("Transfer without sender or recipient");
|
||||||
|
|
||||||
else if (((OutgoingTransfer) transaction).getSender().equals(account))
|
else if (((OutgoingTransfer) transaction).getSender().equals(account))
|
||||||
@@ -332,8 +332,16 @@ public class PrivateBank implements Bank, JsonSerializer<Transaction>, JsonDeser
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Transaction> getTransactionsSorted(String account, boolean asc) {
|
public List<Transaction> getTransactionsSorted(String account, boolean asc) {
|
||||||
List<Transaction> transactions = this.accountsToTransactions.get(account);
|
List<Transaction> transactions = new ArrayList<>(this.accountsToTransactions.get(account));
|
||||||
|
|
||||||
|
if (transactions == null || transactions.isEmpty())
|
||||||
|
return new ArrayList<>();
|
||||||
|
|
||||||
|
if (asc)
|
||||||
transactions.sort(Comparator.comparingDouble(Transaction::calculate));
|
transactions.sort(Comparator.comparingDouble(Transaction::calculate));
|
||||||
|
else
|
||||||
|
transactions.sort(Comparator.comparingDouble(Transaction::calculate).reversed());
|
||||||
|
|
||||||
return transactions;
|
return transactions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,7 +354,8 @@ public class PrivateBank implements Bank, JsonSerializer<Transaction>, JsonDeser
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Transaction> getTransactionsByType(String account, boolean positive) {
|
public List<Transaction> getTransactionsByType(String account, boolean positive) {
|
||||||
List<Transaction> transactions = this.accountsToTransactions.get(account);
|
// an der Kopie der Liste Arbeiten oder nur Filtern und nicht entfernen
|
||||||
|
List<Transaction> transactions = new ArrayList<>(this.accountsToTransactions.get(account));
|
||||||
if (positive)
|
if (positive)
|
||||||
transactions.removeIf(transaction -> transaction.calculate() >= 0);
|
transactions.removeIf(transaction -> transaction.calculate() >= 0);
|
||||||
else
|
else
|
||||||
@@ -354,12 +363,53 @@ public class PrivateBank implements Bank, JsonSerializer<Transaction>, JsonDeser
|
|||||||
return transactions;
|
return transactions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delets an existing account
|
||||||
|
*
|
||||||
|
* @param account the account to be deleted
|
||||||
|
* @throws AccountDoesNotExistException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteAccount(String account) throws AccountDoesNotExistException, IOException {
|
||||||
|
if (this.containsAccount(account)) {
|
||||||
|
// delete account
|
||||||
|
this.accountsToTransactions.remove(account);
|
||||||
|
|
||||||
|
// delete corresponding JSON file
|
||||||
|
String filename = directoryName + "/" + account + ".json";
|
||||||
|
File file = new File(filename);
|
||||||
|
if (!file.delete())
|
||||||
|
throw new IOException("Datei des Accounts: " + account + " konnte nicht richtig gelöscht werden.");
|
||||||
|
} else {
|
||||||
|
throw new AccountDoesNotExistException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of all account names
|
||||||
|
*
|
||||||
|
* @return List of all accounts
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<String> getAllAccounts() {
|
||||||
|
List<String> accounts = new ArrayList<>();
|
||||||
|
|
||||||
|
this.accountsToTransactions.forEach(
|
||||||
|
(account, transactions) -> {
|
||||||
|
accounts.add(account);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return accounts;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Import Accounts from existing JSON Files
|
* Import Accounts from existing JSON Files
|
||||||
*
|
*
|
||||||
* @throws IOException if an error occurs while deserializing
|
* @throws IOException if an error occurs while deserializing
|
||||||
*/
|
*/
|
||||||
public void readAccounts() throws IOException, java.io.IOException, AccountAlreadyExistsException, TransactionAlreadyExistException, AccountDoesNotExistException, TransactionAttributeException {
|
public void readAccounts() throws IOException, AccountAlreadyExistsException, TransactionAlreadyExistException, TransactionAttributeException {
|
||||||
/*
|
/*
|
||||||
1. JSONs einlesen
|
1. JSONs einlesen
|
||||||
2. for each Transaction
|
2. for each Transaction
|
||||||
@@ -367,23 +417,30 @@ public class PrivateBank implements Bank, JsonSerializer<Transaction>, JsonDeser
|
|||||||
2. Objekte in einer Liste zusammenführen
|
2. Objekte in einer Liste zusammenführen
|
||||||
3. Konto mit einer Liste von Transaktionen erzeugen
|
3. Konto mit einer Liste von Transaktionen erzeugen
|
||||||
*/
|
*/
|
||||||
List<Transaction> transactions = new ArrayList<>();
|
|
||||||
|
|
||||||
File directory = new File(directoryName);
|
File directory = new File(directoryName);
|
||||||
File[] files = directory.listFiles();
|
File[] files = directory.listFiles();
|
||||||
|
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
// jedes file ist ein Konto
|
// jedes file ist ein Konto
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
|
List<Transaction> transactions;
|
||||||
String accountName = file.getName().substring(0, file.getName().lastIndexOf("."));
|
String accountName = file.getName().substring(0, file.getName().lastIndexOf("."));
|
||||||
|
String jsonContent;
|
||||||
|
|
||||||
|
try {
|
||||||
|
jsonContent = Files.readString(Paths.get(directoryName + "/" + file.getName()));
|
||||||
|
} catch (java.io.IOException e) {
|
||||||
|
System.out.println("Zum Account: " + accountName + " konnte die Datei nicht geöffnet werden");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
String jsonContent = Files.readString(Paths.get(directoryName + "/" + file.getName()));
|
|
||||||
JsonElement accountData = JsonParser.parseString(jsonContent);
|
JsonElement accountData = JsonParser.parseString(jsonContent);
|
||||||
|
|
||||||
for (JsonElement account : accountData.getAsJsonArray()) {
|
try {
|
||||||
JsonObject accountObject = account.getAsJsonObject();
|
transactions = readAccountHelper(accountData, accountName);
|
||||||
Transaction t = deserialize(accountObject, null, null);
|
} catch (IOException e) {
|
||||||
transactions.add(t);
|
System.out.println(e);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
createAccount(accountName, transactions);
|
createAccount(accountName, transactions);
|
||||||
@@ -391,6 +448,21 @@ public class PrivateBank implements Bank, JsonSerializer<Transaction>, JsonDeser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Transaction> readAccountHelper(JsonElement accountData, String accountName) throws IOException {
|
||||||
|
List<Transaction> transactions = new ArrayList<>();
|
||||||
|
for (JsonElement account : accountData.getAsJsonArray()) {
|
||||||
|
JsonObject accountObject = account.getAsJsonObject();
|
||||||
|
Transaction t;
|
||||||
|
try {
|
||||||
|
t = deserialize(accountObject, null, null);
|
||||||
|
} catch (JsonParseException e) {
|
||||||
|
throw new IOException("Fehler beim Laden des Accounts: " + accountName);
|
||||||
|
}
|
||||||
|
transactions.add(t);
|
||||||
|
}
|
||||||
|
return transactions;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export Account to JSON
|
* Export Account to JSON
|
||||||
*
|
*
|
||||||
@@ -407,7 +479,11 @@ public class PrivateBank implements Bank, JsonSerializer<Transaction>, JsonDeser
|
|||||||
List<Transaction> transactions = this.accountsToTransactions.get(account);
|
List<Transaction> transactions = this.accountsToTransactions.get(account);
|
||||||
|
|
||||||
for (Transaction transaction : transactions)
|
for (Transaction transaction : transactions)
|
||||||
|
try {
|
||||||
accountData.add(serialize(transaction, null, null));
|
accountData.add(serialize(transaction, null, null));
|
||||||
|
} catch (JsonParseException e) {
|
||||||
|
throw new IOException("Fehler beim Speichern des Accounts: " + account);
|
||||||
|
}
|
||||||
|
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||||
String filename = directoryName + "/" + account + ".json";
|
String filename = directoryName + "/" + account + ".json";
|
||||||
@@ -450,8 +526,9 @@ public class PrivateBank implements Bank, JsonSerializer<Transaction>, JsonDeser
|
|||||||
case "Payment":
|
case "Payment":
|
||||||
return new Payment(date, amount, description, transactionInstance.get("incomingInterest").getAsDouble(), transactionInstance.get("outgoingInterest").getAsDouble());
|
return new Payment(date, amount, description, transactionInstance.get("incomingInterest").getAsDouble(), transactionInstance.get("outgoingInterest").getAsDouble());
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new JsonParseException("Unknown transaction type: " + transactionType);
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -474,7 +551,8 @@ public class PrivateBank implements Bank, JsonSerializer<Transaction>, JsonDeser
|
|||||||
|
|
||||||
else if (transaction instanceof Payment)
|
else if (transaction instanceof Payment)
|
||||||
rootObject.addProperty("CLASSNAME", "Payment");
|
rootObject.addProperty("CLASSNAME", "Payment");
|
||||||
|
else
|
||||||
|
throw new JsonParseException("Unknown transaction type: " + transaction.getClass().getName());
|
||||||
|
|
||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
|
||||||
@@ -499,4 +577,6 @@ public class PrivateBank implements Bank, JsonSerializer<Transaction>, JsonDeser
|
|||||||
|
|
||||||
return rootObject;
|
return rootObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package bank.exceptions;
|
package bank.exceptions;
|
||||||
|
|
||||||
public class IOException extends Exception {
|
public class IOException extends Exception {
|
||||||
public IOException() {
|
public IOException(String message) {
|
||||||
super("Fehler in der De-/ Serialisierung der Daten");
|
super("Fehler in der De-/ Serialisierung der Daten. " + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
333
src/main/java/ui/AccountviewController.java
Normal file
333
src/main/java/ui/AccountviewController.java
Normal file
@@ -0,0 +1,333 @@
|
|||||||
|
package ui;
|
||||||
|
|
||||||
|
import bank.PrivateBank;
|
||||||
|
import bank.Transaction;
|
||||||
|
import bank.exceptions.AccountDoesNotExistException;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class AccountviewController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label accountNameLabel;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label balanceLabel;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ListView<Transaction> transactionListView;
|
||||||
|
|
||||||
|
private PrivateBank privateBank;
|
||||||
|
private String currentAccount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a second copied instance of a Bank
|
||||||
|
*
|
||||||
|
* @param accountName
|
||||||
|
* @param bank
|
||||||
|
*/
|
||||||
|
public void setAccount(String accountName, PrivateBank bank) {
|
||||||
|
this.currentAccount = accountName;
|
||||||
|
this.privateBank = bank;
|
||||||
|
updateAccountInfo();
|
||||||
|
loadTransactions();
|
||||||
|
|
||||||
|
// Kontextmenü erstellen
|
||||||
|
ContextMenu contextMenu = new ContextMenu();
|
||||||
|
|
||||||
|
// Kontextmenü-Items definieren
|
||||||
|
MenuItem deleteItem = new MenuItem("Löschen");
|
||||||
|
|
||||||
|
// Kontextmenü-Item Aktion: Transaktion löschen
|
||||||
|
deleteItem.setOnAction(
|
||||||
|
event -> {
|
||||||
|
Transaction selectedTransaction = transactionListView.getSelectionModel().getSelectedItem();
|
||||||
|
if (selectedTransaction != null) {
|
||||||
|
boolean confirmed = showDeleteConfirmation(selectedTransaction);
|
||||||
|
if (confirmed) {
|
||||||
|
Alert errorAlert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
errorAlert.setTitle("Fehler");
|
||||||
|
try {
|
||||||
|
privateBank.removeTransaction(currentAccount, selectedTransaction);
|
||||||
|
transactionListView.getItems().remove(selectedTransaction);
|
||||||
|
updateAccountInfo();
|
||||||
|
} catch (AccountDoesNotExistException e) {
|
||||||
|
errorAlert.setHeaderText("Account existiert nicht");
|
||||||
|
errorAlert.setContentText("Der Account \"" + currentAccount + "\" existiert nicht.");
|
||||||
|
errorAlert.showAndWait();
|
||||||
|
} catch (bank.exceptions.IOException e) {
|
||||||
|
errorAlert.setHeaderText("Account JSON Fehler");
|
||||||
|
errorAlert.setContentText("Die JSON des Accounts \"" + currentAccount + "\" konnte nicht bearbeitet werden.");
|
||||||
|
errorAlert.showAndWait();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
errorAlert.setHeaderText("Transaktion konnte nicht gelöscht werden.");
|
||||||
|
errorAlert.setContentText("Es ist ein unerwarteter Fehler aufgetreten.");
|
||||||
|
errorAlert.showAndWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Kontextmenü-Items dem Kontextmenü hinzufügen
|
||||||
|
contextMenu.getItems().add(deleteItem);
|
||||||
|
|
||||||
|
// An ListView binden
|
||||||
|
transactionListView.setContextMenu(contextMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the labels of an account
|
||||||
|
*/
|
||||||
|
private void updateAccountInfo() {
|
||||||
|
double balance = this.privateBank.getAccountBalance(currentAccount);
|
||||||
|
|
||||||
|
accountNameLabel.setText("Account: " + currentAccount);
|
||||||
|
balanceLabel.setText("Balance: " + balance);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadTransactions() {
|
||||||
|
showTransactions(this.privateBank.getTransactions(currentAccount));
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onBackButtonClicked() {
|
||||||
|
try {
|
||||||
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("/Mainview.fxml"));
|
||||||
|
Parent root = loader.load();
|
||||||
|
|
||||||
|
Stage stage = (Stage) transactionListView.getScene().getWindow();
|
||||||
|
stage.getScene().setRoot(root);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onSortAscending() {
|
||||||
|
showTransactions(this.privateBank.getTransactionsSorted(currentAccount, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onSortDescending() {
|
||||||
|
showTransactions(this.privateBank.getTransactionsSorted(currentAccount, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onShowPositive() {
|
||||||
|
showTransactions(this.privateBank.getTransactionsByType(currentAccount, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onShowNegative() {
|
||||||
|
showTransactions(this.privateBank.getTransactionsByType(currentAccount, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onShowAll() {
|
||||||
|
showTransactions(this.privateBank.getTransactions(currentAccount));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Listview of transaction based on a given list
|
||||||
|
*
|
||||||
|
* @param transactions
|
||||||
|
*/
|
||||||
|
private void showTransactions(List<Transaction> transactions) {
|
||||||
|
transactionListView.getItems().setAll(transactions);
|
||||||
|
updateAccountInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Confirmation of transaction delete
|
||||||
|
*
|
||||||
|
* @param transaction transaction to be deleted
|
||||||
|
* @return confirmation
|
||||||
|
*/
|
||||||
|
private boolean showDeleteConfirmation(Transaction transaction) {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
||||||
|
alert.setTitle("Transaktion löschen");
|
||||||
|
alert.setHeaderText("Soll die Transaktion wirklich gelöscht werden?");
|
||||||
|
alert.setContentText("Transaktion:\n" + transaction.toString() + "\n\nDiese Aktion kann nicht rückgängig gemacht werden.");
|
||||||
|
|
||||||
|
ButtonType yesButton = new ButtonType("Ja", ButtonBar.ButtonData.YES);
|
||||||
|
ButtonType noButton = new ButtonType("Nein", ButtonBar.ButtonData.NO);
|
||||||
|
|
||||||
|
alert.getButtonTypes().setAll(yesButton, noButton);
|
||||||
|
|
||||||
|
Optional<ButtonType> result = alert.showAndWait();
|
||||||
|
return result.isPresent() && result.get() == yesButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates user inputs for adding transaction
|
||||||
|
*
|
||||||
|
* @param typeComboBox
|
||||||
|
* @param amountField
|
||||||
|
* @param descriptionField
|
||||||
|
* @param senderReceiverField
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean validateTransactionInput(ComboBox<String> typeComboBox, TextField amountField, TextField descriptionField, TextField senderField, TextField recieverField) {
|
||||||
|
String type = typeComboBox.getValue();
|
||||||
|
String amountStr = amountField.getText().trim();
|
||||||
|
String desc = descriptionField.getText().trim();
|
||||||
|
|
||||||
|
// Basis-Checks
|
||||||
|
if (desc.isEmpty())
|
||||||
|
return false;
|
||||||
|
try {
|
||||||
|
double amount = Double.parseDouble(amountStr);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type.equals("Überweisung")) {
|
||||||
|
String sender = senderField.getText().trim();
|
||||||
|
String reciever = recieverField.getText().trim();
|
||||||
|
|
||||||
|
return (sender.equals(currentAccount) || reciever.equals(currentAccount)) &&
|
||||||
|
!sender.equals(reciever) &&
|
||||||
|
!sender.isEmpty() && !reciever.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<Transaction> showNewTransactionDialog() {
|
||||||
|
Dialog<Transaction> dialog = new Dialog<>();
|
||||||
|
dialog.setTitle("Neue Transaktion");
|
||||||
|
dialog.setHeaderText("Bitte geben Sie die Daten der neuen Transaktion ein.");
|
||||||
|
|
||||||
|
// Buttons
|
||||||
|
ButtonType okButton = new ButtonType("Hinzufügen", ButtonBar.ButtonData.OK_DONE);
|
||||||
|
ButtonType cancelButton = new ButtonType("Abbrechen", ButtonBar.ButtonData.CANCEL_CLOSE);
|
||||||
|
dialog.getDialogPane().getButtonTypes().addAll(okButton, cancelButton);
|
||||||
|
|
||||||
|
// UI-Elemente
|
||||||
|
Label dateLabel = new Label("Datum:");
|
||||||
|
TextField dateField = new TextField();
|
||||||
|
|
||||||
|
Label typeLabel = new Label("Typ:");
|
||||||
|
ComboBox<String> typeComboBox = new ComboBox<>();
|
||||||
|
typeComboBox.getItems().addAll("Ein-/Auszahlung", "Überweisung");
|
||||||
|
typeComboBox.getSelectionModel().selectFirst(); // Default Payment
|
||||||
|
|
||||||
|
Label amountLabel = new Label("Betrag:");
|
||||||
|
TextField amountField = new TextField();
|
||||||
|
|
||||||
|
Label descriptionLabel = new Label("Beschreibung:");
|
||||||
|
TextField descriptionField = new TextField();
|
||||||
|
|
||||||
|
Label senderLabel = new Label("Sender:");
|
||||||
|
TextField senderField = new TextField();
|
||||||
|
Label recieverLabel = new Label("Empfänger:");
|
||||||
|
TextField recieverField = new TextField();
|
||||||
|
|
||||||
|
// Layout
|
||||||
|
GridPane grid = new GridPane();
|
||||||
|
grid.setHgap(10);
|
||||||
|
grid.setVgap(10);
|
||||||
|
|
||||||
|
grid.add(typeLabel, 0, 0);
|
||||||
|
grid.add(typeComboBox, 1, 0);
|
||||||
|
|
||||||
|
grid.add(dateLabel, 0, 1);
|
||||||
|
grid.add(dateField, 1, 1);
|
||||||
|
|
||||||
|
grid.add(amountLabel, 0, 2);
|
||||||
|
grid.add(amountField, 1, 2);
|
||||||
|
|
||||||
|
grid.add(descriptionLabel, 0, 3);
|
||||||
|
grid.add(descriptionField, 1, 3);
|
||||||
|
|
||||||
|
grid.add(senderLabel, 0, 4);
|
||||||
|
grid.add(senderField, 1, 4);
|
||||||
|
|
||||||
|
grid.add(recieverLabel, 0, 5);
|
||||||
|
grid.add(recieverField, 1, 5);
|
||||||
|
|
||||||
|
dialog.getDialogPane().setContent(grid);
|
||||||
|
|
||||||
|
// OK-Button Validation
|
||||||
|
Node okBtnNode = dialog.getDialogPane().lookupButton(okButton);
|
||||||
|
okBtnNode.addEventFilter(ActionEvent.ACTION, event -> {
|
||||||
|
// Validierung
|
||||||
|
if (!validateTransactionInput(typeComboBox, amountField, descriptionField, senderField, recieverField)) {
|
||||||
|
event.consume(); // Verhindere schließen des Dialogs
|
||||||
|
Alert alert = new Alert(Alert.AlertType.WARNING);
|
||||||
|
alert.setTitle("Ungültige Eingabe");
|
||||||
|
alert.setHeaderText("Bitte alle Felder korrekt ausfüllen.");
|
||||||
|
alert.setContentText("- der Betrag muss eine Zahl sein \n- die Beschreibung darf nicht leer sein.\n " +
|
||||||
|
"- bei einer Überweisung dürfen Sender & Empfänger nicht leer und nicht gleich sein");
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dialog.setResultConverter(dialogButton -> {
|
||||||
|
if (dialogButton == okButton) {
|
||||||
|
try {
|
||||||
|
String type = typeComboBox.getValue();
|
||||||
|
double amount = Double.parseDouble(amountField.getText());
|
||||||
|
String description = descriptionField.getText().trim();
|
||||||
|
String date = dateField.getText().trim();
|
||||||
|
if (dateField.getText().trim().isEmpty())
|
||||||
|
date = LocalDate.now().toString();
|
||||||
|
|
||||||
|
if (type.equals("Ein-/Auszahlung")) {
|
||||||
|
return new bank.Payment(date, amount, description);
|
||||||
|
} else {
|
||||||
|
String recieverAccount = recieverField.getText().trim();
|
||||||
|
String senderAccount = senderField.getText().trim();
|
||||||
|
|
||||||
|
if (recieverAccount.isEmpty() && senderAccount.isEmpty() || recieverAccount.equals(senderAccount))
|
||||||
|
return null;
|
||||||
|
else if (senderAccount.equals(currentAccount))
|
||||||
|
return new bank.OutgoingTransfer(date, amount, description, currentAccount, recieverAccount);
|
||||||
|
else if (recieverAccount.equals(currentAccount))
|
||||||
|
return new bank.IncomingTransfer(date, amount, description, recieverAccount, currentAccount);
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// Sollte nie hier landen, da oben schon abgefangen, aber falls doch:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
return dialog.showAndWait();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onNewTransactionClicked() {
|
||||||
|
Optional<Transaction> transactionOpt = showNewTransactionDialog();
|
||||||
|
if (transactionOpt.isPresent()) {
|
||||||
|
Transaction transaction = transactionOpt.get();
|
||||||
|
try {
|
||||||
|
privateBank.addTransaction(currentAccount, transaction);
|
||||||
|
loadTransactions(); // Liste neu laden, um neue Transaktion anzuzeigen
|
||||||
|
updateAccountInfo(); // Kontostand aktualisieren
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Fehler beim Hinzufügen anzeigen
|
||||||
|
Alert errorAlert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
errorAlert.setTitle("Fehler");
|
||||||
|
errorAlert.setHeaderText("Transaktion konnte nicht hinzugefügt werden.");
|
||||||
|
errorAlert.setContentText("Überprüfen Sie Ihre Eingaben oder versuchen Sie es später erneut.");
|
||||||
|
errorAlert.showAndWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
180
src/main/java/ui/MainviewController.java
Normal file
180
src/main/java/ui/MainviewController.java
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
package ui;
|
||||||
|
|
||||||
|
import bank.PrivateBank;
|
||||||
|
|
||||||
|
import bank.exceptions.AccountAlreadyExistsException;
|
||||||
|
import bank.exceptions.IOException;
|
||||||
|
|
||||||
|
import javafx.fxml.*;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.input.MouseButton;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
|
public class MainviewController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ListView<String> accountListView;
|
||||||
|
|
||||||
|
private PrivateBank privateBank; // Referenz auf Ihr Bankobjekt
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void initialize() {
|
||||||
|
// Bank initialisieren
|
||||||
|
this.privateBank = main.getPrivateBank();
|
||||||
|
|
||||||
|
// Zeige alle vorhandenen Konten an
|
||||||
|
accountListView.getItems().addAll(privateBank.getAllAccounts());
|
||||||
|
|
||||||
|
// Kontextmenü definieren
|
||||||
|
ContextMenu contextMenu = new ContextMenu();
|
||||||
|
|
||||||
|
// Kontextmenü-Items definieren
|
||||||
|
MenuItem selectItem = new MenuItem("Auswählen");
|
||||||
|
MenuItem deleteItem = new MenuItem("Löschen");
|
||||||
|
|
||||||
|
// Kontextmenü-Item Aktion: Konto auswählen
|
||||||
|
selectItem.setOnAction(
|
||||||
|
event -> {
|
||||||
|
String selectedAccount = accountListView.getSelectionModel().getSelectedItem();
|
||||||
|
if (selectedAccount != null)
|
||||||
|
switchToAccountView(selectedAccount);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Kontextmenü-Item Aktion: Konto löschen
|
||||||
|
deleteItem.setOnAction(
|
||||||
|
event -> {
|
||||||
|
String selectedAccount = accountListView.getSelectionModel().getSelectedItem();
|
||||||
|
if (selectedAccount != null) {
|
||||||
|
boolean confirmed = showDeleteConfirmation(selectedAccount);
|
||||||
|
if (confirmed) {
|
||||||
|
// Account löschen
|
||||||
|
try {
|
||||||
|
privateBank.deleteAccount(selectedAccount);
|
||||||
|
// ListView aktualisieren
|
||||||
|
accountListView.getItems().remove(selectedAccount);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Kontextmenü-Items dem Kontextmenü hinzufügen
|
||||||
|
contextMenu.getItems().addAll(selectItem, deleteItem);
|
||||||
|
|
||||||
|
// Kontextmenü an die ListView binden
|
||||||
|
accountListView.setContextMenu(contextMenu);
|
||||||
|
|
||||||
|
// Optional: Double-Click zum Auswählen ohne Kontextmenü
|
||||||
|
accountListView.setOnMouseClicked(
|
||||||
|
event -> {
|
||||||
|
if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) {
|
||||||
|
String selectedAccount = accountListView.getSelectionModel().getSelectedItem();
|
||||||
|
if (selectedAccount != null) {
|
||||||
|
switchToAccountView(selectedAccount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param accountName
|
||||||
|
*/
|
||||||
|
private void switchToAccountView(String accountName) {
|
||||||
|
try {
|
||||||
|
// Laden der zweiten FXML
|
||||||
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("/Accountview.fxml"));
|
||||||
|
Parent root = loader.load();
|
||||||
|
|
||||||
|
// Zugriff auf Controller und Datenübergabe
|
||||||
|
AccountviewController accountController = loader.getController();
|
||||||
|
accountController.setAccount(accountName, privateBank);
|
||||||
|
|
||||||
|
// Scene in derselben Stage wechseln
|
||||||
|
Stage stage = (Stage) accountListView.getScene().getWindow();
|
||||||
|
stage.getScene().setRoot(root);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param accountName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean showDeleteConfirmation(String accountName) {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
||||||
|
alert.setTitle("Account löschen");
|
||||||
|
alert.setHeaderText("Soll der Account '" + accountName + "' wirklich gelöscht werden?");
|
||||||
|
alert.setContentText("Diese Aktion kann nicht rückgängig gemacht werden.");
|
||||||
|
|
||||||
|
ButtonType yesButton = new ButtonType("Ja", ButtonBar.ButtonData.YES);
|
||||||
|
ButtonType noButton = new ButtonType("Nein", ButtonBar.ButtonData.NO);
|
||||||
|
|
||||||
|
alert.getButtonTypes().setAll(yesButton, noButton);
|
||||||
|
|
||||||
|
Optional<ButtonType> result = alert.showAndWait();
|
||||||
|
|
||||||
|
return result.isPresent() && result.get() == yesButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onNewAccountClicked() {
|
||||||
|
// Dialog zum Eingeben eines neuen Account-Namens
|
||||||
|
TextInputDialog dialog = new TextInputDialog();
|
||||||
|
dialog.setTitle("Neuen Account erstellen");
|
||||||
|
dialog.setHeaderText("Bitte geben Sie den Namen des neuen Accounts ein:");
|
||||||
|
dialog.setContentText("Account-Name:");
|
||||||
|
|
||||||
|
Optional<String> result = dialog.showAndWait();
|
||||||
|
if (result.isPresent()) {
|
||||||
|
String newAccountName = result.get().trim();
|
||||||
|
if (!newAccountName.isEmpty()) {
|
||||||
|
Alert errorAlert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
errorAlert.setTitle("Fehler");
|
||||||
|
try {
|
||||||
|
// Account erstellen
|
||||||
|
privateBank.createAccount(newAccountName);
|
||||||
|
privateBank.writeAccount(newAccountName);
|
||||||
|
|
||||||
|
// neuen Account der Listview hinzufügen
|
||||||
|
if (!accountListView.getItems().contains(newAccountName))
|
||||||
|
accountListView.getItems().add(newAccountName);
|
||||||
|
|
||||||
|
} catch (AccountAlreadyExistsException e) {
|
||||||
|
errorAlert.setHeaderText("Account existiert bereits");
|
||||||
|
errorAlert.setContentText("Der Account \"" + newAccountName + "\" wurde bereits angelegt.");
|
||||||
|
errorAlert.showAndWait();
|
||||||
|
} catch (IOException e) {
|
||||||
|
errorAlert.setHeaderText("Account JSON Fehler");
|
||||||
|
errorAlert.setContentText("Die JSON des Accounts \"" + newAccountName + "\" konnte nicht bearbeitet werden.");
|
||||||
|
errorAlert.showAndWait();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
errorAlert.setHeaderText("Account konnte nicht erstellt werden.");
|
||||||
|
errorAlert.setContentText("Überprüfen Sie, ob der Name bereits existiert oder ein anderer Fehler vorliegt.");
|
||||||
|
errorAlert.showAndWait();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Leeren Namen nicht akzeptieren
|
||||||
|
Alert alert = new Alert(Alert.AlertType.WARNING);
|
||||||
|
alert.setTitle("Warnung");
|
||||||
|
alert.setHeaderText("Ungültiger Account-Name");
|
||||||
|
alert.setContentText("Bitte geben Sie einen gültigen Namen ein.");
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
48
src/main/java/ui/main.java
Normal file
48
src/main/java/ui/main.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package ui;
|
||||||
|
|
||||||
|
import bank.PrivateBank;
|
||||||
|
import bank.exceptions.AccountAlreadyExistsException;
|
||||||
|
import bank.exceptions.IOException;
|
||||||
|
import bank.exceptions.TransactionAlreadyExistException;
|
||||||
|
import bank.exceptions.TransactionAttributeException;
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class main extends Application {
|
||||||
|
/**
|
||||||
|
* Starting point
|
||||||
|
*
|
||||||
|
* @param primaryStage
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void start(Stage primaryStage) throws Exception {
|
||||||
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("/Mainview.fxml"));
|
||||||
|
Scene scene = new Scene(loader.load());
|
||||||
|
primaryStage.setScene(scene);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PrivateBank privateBank = new PrivateBank(
|
||||||
|
"Bank1",
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
"accountdata");
|
||||||
|
|
||||||
|
public static PrivateBank getPrivateBank() {
|
||||||
|
try {
|
||||||
|
privateBank.readAccounts();
|
||||||
|
} catch (IOException | AccountAlreadyExistsException | TransactionAlreadyExistException |
|
||||||
|
TransactionAttributeException e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
return privateBank;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
39
src/main/resources/Accountview.fxml
Normal file
39
src/main/resources/Accountview.fxml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<BorderPane fx:id="root" xmlns="http://javafx.com/javafx"
|
||||||
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
|
fx:controller="ui.AccountviewController">
|
||||||
|
|
||||||
|
<top>
|
||||||
|
<HBox spacing="10" alignment="CENTER_LEFT">
|
||||||
|
<!-- Back Button -->
|
||||||
|
<Button text="Back" fx:id="backButton" onAction="#onBackButtonClicked"/>
|
||||||
|
|
||||||
|
<Button text="Neue Transaktion" onAction="#onNewTransactionClicked"/>
|
||||||
|
|
||||||
|
<!-- Account Name Label -->
|
||||||
|
<Label fx:id="accountNameLabel" text="Account: "/>
|
||||||
|
|
||||||
|
<!-- Balance Label -->
|
||||||
|
<Label fx:id="balanceLabel" text="Balance: "/>
|
||||||
|
</HBox>
|
||||||
|
</top>
|
||||||
|
|
||||||
|
<center>
|
||||||
|
<!-- List of Accounts Transactions -->
|
||||||
|
<ListView fx:id="transactionListView" />
|
||||||
|
</center>
|
||||||
|
|
||||||
|
<bottom>
|
||||||
|
<HBox spacing="10" alignment="CENTER">
|
||||||
|
<!-- Buttons for Sorting -->
|
||||||
|
<Button text="Aufsteigend sortieren" onAction="#onSortAscending"/>
|
||||||
|
<Button text="Absteigend sortieren" onAction="#onSortDescending"/>
|
||||||
|
<Button text="Nur positive" onAction="#onShowPositive"/>
|
||||||
|
<Button text="Nur negative" onAction="#onShowNegative"/>
|
||||||
|
<Button text="Alle anzeigen" onAction="#onShowAll"/>
|
||||||
|
</HBox>
|
||||||
|
</bottom>
|
||||||
|
</BorderPane>
|
||||||
21
src/main/resources/Mainview.fxml
Normal file
21
src/main/resources/Mainview.fxml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<BorderPane fx:id="root" xmlns="http://javafx.com/javafx"
|
||||||
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
|
fx:controller="ui.MainviewController">
|
||||||
|
<top>
|
||||||
|
<MenuBar>
|
||||||
|
<Menu text="Datei">
|
||||||
|
<MenuItem text="Neu" onAction="#onNewAccountClicked"/>
|
||||||
|
</Menu>
|
||||||
|
</MenuBar>
|
||||||
|
</top>
|
||||||
|
|
||||||
|
<center>
|
||||||
|
<ListView fx:id="accountListView"/>
|
||||||
|
</center>
|
||||||
|
</BorderPane>
|
||||||
|
|
||||||
|
|
||||||
@@ -6,9 +6,6 @@ import org.junit.jupiter.params.provider.CsvSource;
|
|||||||
import org.junit.jupiter.params.provider.ValueSource;
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
@@ -23,7 +20,7 @@ public class PrivateBankTest {
|
|||||||
|
|
||||||
@DisplayName("Set up a PrivateBank")
|
@DisplayName("Set up a PrivateBank")
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void init() throws AccountAlreadyExistsException, IOException, TransactionAlreadyExistException,
|
public static void init() throws AccountAlreadyExistsException, TransactionAlreadyExistException,
|
||||||
AccountDoesNotExistException, TransactionAttributeException {
|
AccountDoesNotExistException, TransactionAttributeException {
|
||||||
|
|
||||||
String path = "accountdata";
|
String path = "accountdata";
|
||||||
@@ -359,7 +356,7 @@ public class PrivateBankTest {
|
|||||||
@Test
|
@Test
|
||||||
@Order(16)
|
@Order(16)
|
||||||
public void getTransactionsByTypeTest() {
|
public void getTransactionsByTypeTest() {
|
||||||
List<Transaction> transactionList = List.of(
|
List<Transaction> transactionsPositive = List.of(
|
||||||
new IncomingTransfer(
|
new IncomingTransfer(
|
||||||
"01.01.2000",
|
"01.01.2000",
|
||||||
300,
|
300,
|
||||||
@@ -368,14 +365,30 @@ public class PrivateBankTest {
|
|||||||
"Konto_1"
|
"Konto_1"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
List<Transaction> transactionsNegative = List.of(
|
||||||
|
new Payment(
|
||||||
|
"01.01.2000",
|
||||||
|
-100,
|
||||||
|
"Payment",
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
transactionList,
|
transactionsPositive,
|
||||||
privateBank.getTransactionsByType(
|
privateBank.getTransactionsByType(
|
||||||
"Konto_1",
|
"Konto_1",
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
System.out.println("getTransactionByTypeTest in <Konto_1> is correct.");
|
assertEquals(
|
||||||
|
transactionsNegative,
|
||||||
|
privateBank.getTransactionsByType(
|
||||||
|
"Konto_1",
|
||||||
|
true
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -411,9 +424,39 @@ public class PrivateBankTest {
|
|||||||
true
|
true
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
List.of(
|
||||||
|
new IncomingTransfer(
|
||||||
|
"01.01.2000",
|
||||||
|
300,
|
||||||
|
"IncomingTransfer from Tom",
|
||||||
|
"Tom",
|
||||||
|
"Konto_6"
|
||||||
|
),
|
||||||
|
new IncomingTransfer(
|
||||||
|
"01.01.2000",
|
||||||
|
100,
|
||||||
|
"IncomingTransfer from Hans",
|
||||||
|
"Hans",
|
||||||
|
"Konto_6"
|
||||||
|
),
|
||||||
|
new OutgoingTransfer(
|
||||||
|
"01.01.2000",
|
||||||
|
100,
|
||||||
|
"OutgoingTransfer to Hans",
|
||||||
|
"Konto_6",
|
||||||
|
"Hans"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
privateBank.getTransactionsSorted(
|
||||||
|
"Konto_6",
|
||||||
|
false
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("Serialize Accounts")
|
@DisplayName("Serialize existing Accounts")
|
||||||
@Order(18)
|
@Order(18)
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@ValueSource(strings = {"Konto_1", "Konto_2", "Konto_3", "Konto_4", "Konto_5", "Konto_6", "Konto_7", "Konto_8"})
|
@ValueSource(strings = {"Konto_1", "Konto_2", "Konto_3", "Konto_4", "Konto_5", "Konto_6", "Konto_7", "Konto_8"})
|
||||||
@@ -424,12 +467,87 @@ public class PrivateBankTest {
|
|||||||
System.out.println("SerializeAccountsTest in <" + account + "> is correct.");
|
System.out.println("SerializeAccountsTest in <" + account + "> is correct.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@DisplayName("Deserialize Accounts")
|
@DisplayName("Deserialize existing Accounts")
|
||||||
@Order(19)
|
@Order(19)
|
||||||
@Test
|
@Test
|
||||||
public void DeserializeAccountsTest() {
|
public void DeserializeAccountsTest() {
|
||||||
|
// Die eingelesenen Konten sind bereits vorhanden
|
||||||
assertThrows(
|
assertThrows(
|
||||||
AccountAlreadyExistsException.class, () -> privateBank.readAccounts()
|
AccountAlreadyExistsException.class, () -> privateBank.readAccounts()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DisplayName("Delete existing account")
|
||||||
|
@Order(20)
|
||||||
|
@Test
|
||||||
|
public void testDeleteExistingAccount() {
|
||||||
|
assertDoesNotThrow(
|
||||||
|
() -> privateBank.createAccount(
|
||||||
|
"Konto_X",
|
||||||
|
List.of(
|
||||||
|
new OutgoingTransfer(
|
||||||
|
"01.01.2000",
|
||||||
|
100,
|
||||||
|
"OutgoingTransfer to Hans",
|
||||||
|
"Konto_X",
|
||||||
|
"Hans"
|
||||||
|
),
|
||||||
|
new IncomingTransfer(
|
||||||
|
"01.01.2000",
|
||||||
|
100,
|
||||||
|
"IncomingTransfer from Hans",
|
||||||
|
"Hans",
|
||||||
|
"Konto_X"
|
||||||
|
),
|
||||||
|
new IncomingTransfer(
|
||||||
|
"01.01.2000",
|
||||||
|
300,
|
||||||
|
"IncomingTransfer from Tom",
|
||||||
|
"Tom",
|
||||||
|
"Konto_X"
|
||||||
|
)
|
||||||
|
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
assertDoesNotThrow(
|
||||||
|
() -> privateBank.writeAccount("Konto_X")
|
||||||
|
);
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
() -> privateBank.containsAccount("Konto_X")
|
||||||
|
);
|
||||||
|
|
||||||
|
assertDoesNotThrow(
|
||||||
|
() -> privateBank.deleteAccount("Konto_X")
|
||||||
|
);
|
||||||
|
|
||||||
|
assertFalse(
|
||||||
|
() -> privateBank.containsAccount("Konto_X")
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("Delete non existing account")
|
||||||
|
@Order(21)
|
||||||
|
@Test
|
||||||
|
public void testDeleteNonExistingAccount() {
|
||||||
|
assertThrows(
|
||||||
|
AccountDoesNotExistException.class, () -> privateBank.deleteAccount("Konto_X")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DisplayName("Get all accounts")
|
||||||
|
@Order(22)
|
||||||
|
@Test
|
||||||
|
public void testGetAllAccounts() {
|
||||||
|
List<String> expectedAccounts = List.of(
|
||||||
|
"Konto_1", "Konto_3", "Konto_2", "Konto_5", "Konto_4", "Konto_7", "Konto_6", "Konto_8"
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
expectedAccounts,
|
||||||
|
privateBank.getAllAccounts()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user