Testweise eine Bank mit UI, Facade und Domain erstellt

main
dustineversmann 2024-10-08 21:10:54 +02:00
parent 12c473accb
commit eb1e178564
8 changed files with 346 additions and 42 deletions

View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

View File

@ -1,11 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CommitMessageInspectionProfile">
<profile version="1.0">
<inspection_tool class="CommitFormat" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="CommitNamingConvention" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>

View File

@ -5,19 +5,50 @@
</component>
<component name="ChangeListManager">
<list default="true" id="e481dbed-92c6-4d5a-b3eb-311b382196d1" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/encodings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/de/deversmann/Main.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/uiDesigner.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/de/deversmann/Account.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/de/deversmann/BankFacade.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/de/deversmann/BankUI.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/de/deversmann/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/de/deversmann/BankApp.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="GitLabMergeRequestFiltersHistory"><![CDATA[{
"lastFilter": {
"state": "OPENED",
"assignee": {
"type": "org.jetbrains.plugins.gitlab.mergerequest.ui.filters.GitLabMergeRequestsFiltersValue.MergeRequestsMemberFilterValue.MergeRequestsAssigneeFilterValue",
"username": "dussel122",
"fullname": "Dustin Eversmann"
}
}
}]]></component>
<component name="GitLabMergeRequestsSettings"><![CDATA[{
"selectedUrlAndAccountId": {
"first": "git@gitlab.com:dussel122/Bank.git",
"second": "dbdfcb9f-d443-4dfb-83bb-dd14a7bde8cc"
}
}]]></component>
<component name="ProjectColorInfo"><![CDATA[{
"customColor": "",
"associatedIndex": 5
}]]></component>
<component name="ProjectId" id="2nAPWZ0rJ3Jb3I8EXy7NrvpSW0P" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
@ -25,7 +56,9 @@
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"Application.BankApp.executor": "Run",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"git-widget-placeholder": "main",
"kotlin-language-version-configured": "true",
"node.js.detected.package.eslint": "true",
@ -38,6 +71,26 @@
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="RunManager">
<configuration name="BankApp" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="de.deversmann.BankApp" />
<module name="Bank" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="de.deversmann.Facade.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.BankApp" />
</list>
</recent_temporary>
</component>
<component name="SharedIndexes">
<attachedChunks>
<set>
@ -54,7 +107,8 @@
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1727259661745</updated>
<workItem from="1727259662688" duration="3934000" />
<workItem from="1727259662688" duration="8998000" />
<workItem from="1728412941018" duration="492000" />
</task>
<servers />
</component>
@ -72,17 +126,6 @@
</map>
</option>
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/de/deversmann/Main.java</url>
<line>13</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
<component name="XSLT-Support.FileAssociations.UIState">
<expand />
<select />

View File

@ -0,0 +1,41 @@
package de.deversmann;
import de.deversmann.Facade.BankFacade;
import de.deversmann.UI.BankUI;
public class BankApp {
public static void main(String[] args) {
BankFacade bankFacade = new BankFacade();
BankUI bankUI = new BankUI(); // Instanz der UI-Klasse
System.out.println("Willkommen bei der BankApp!");
try {
String accountNumber = bankUI.getAccountNumber();
int action = bankUI.getAction();
switch (action) {
case 1:
double depositAmount = bankUI.getDepositAmount();
bankFacade.depositToAccount(accountNumber, depositAmount);
bankUI.showSuccessMessage("Einzahlung erfolgreich.");
break;
case 2:
double withdrawAmount = bankUI.getWithdrawAmount();
bankFacade.withdrawFromAccount(accountNumber, withdrawAmount);
bankUI.showSuccessMessage("Abhebung erfolgreich.");
break;
case 3:
double balance = bankFacade.getAccountBalance(accountNumber);
bankUI.showBalance(balance);
break;
default:
bankUI.showErrorMessage("Ungültige Aktion.");
}
} catch (Exception e) {
bankUI.showErrorMessage(e.getMessage());
} finally {
bankUI.closeScanner(); // Scanner wird geschlossen
}
}
}

View File

@ -0,0 +1,29 @@
package de.deversmann.Domain;
public class Account {
private String accountNumber;
private double balance;
public Account(String accountNumber, double initialBalance) {
this.accountNumber = accountNumber;
this.balance = initialBalance;
}
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
}
}
public void withdraw(double amount) throws Exception {
if (amount > 0 && balance >= amount) {
balance -= amount;
} else {
throw new Exception("Insufficient balance");
}
}
public double getBalance() {
return balance;
}
}

View File

@ -0,0 +1,43 @@
package de.deversmann.Facade;
import de.deversmann.Domain.Account;
import java.util.HashMap;
import java.util.Map;
public class BankFacade {
private Map<String, Account> accounts;
public BankFacade() {
this.accounts = new HashMap<>();
// Beispiel: Erstellen eines Demokontos
accounts.put("12345", new Account("12345", 1000.0));
}
public void depositToAccount(String accountNumber, double amount) throws Exception {
Account account = accounts.get(accountNumber);
if (account != null) {
account.deposit(amount);
} else {
throw new Exception("Account not found");
}
}
public void withdrawFromAccount(String accountNumber, double amount) throws Exception {
Account account = accounts.get(accountNumber);
if (account != null) {
account.withdraw(amount);
} else {
throw new Exception("Account not found");
}
}
public double getAccountBalance(String accountNumber) throws Exception {
Account account = accounts.get(accountNumber);
if (account != null) {
return account.getBalance();
} else {
throw new Exception("Account not found");
}
}
}

View File

@ -1,17 +0,0 @@
package de.deversmann;
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
System.out.printf("Hello and welcome!");
for (int i = 1; i <= 5; i++) {
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
System.out.println("i = " + i);
}
}
}

View File

@ -0,0 +1,47 @@
package de.deversmann.UI;
import java.util.Scanner;
public class BankUI {
private Scanner scanner;
public BankUI() {
this.scanner = new Scanner(System.in);
}
public String getAccountNumber() {
System.out.print("Geben Sie die Kontonummer ein: ");
return scanner.nextLine();
}
public int getAction() {
System.out.print("Wählen Sie eine Aktion (1: Einzahlen, 2: Abheben, 3: Kontostand anzeigen): ");
return scanner.nextInt();
}
public double getDepositAmount() {
System.out.print("Geben Sie den Einzahlungsbetrag ein: ");
return scanner.nextDouble();
}
public double getWithdrawAmount() {
System.out.print("Geben Sie den Abhebungsbetrag ein: ");
return scanner.nextDouble();
}
public void showBalance(double balance) {
System.out.println("Ihr Kontostand beträgt: " + balance);
}
public void showSuccessMessage(String message) {
System.out.println(message);
}
public void showErrorMessage(String message) {
System.out.println("Fehler: " + message);
}
public void closeScanner() {
scanner.close();
}
}