-
Notifications
You must be signed in to change notification settings - Fork 0
/
Account.java
93 lines (86 loc) · 2.99 KB
/
Account.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package de.niklas.exercise.classes;
/**
* <strong>Bankkonto</strong><br>
* Schreiben eines Bankkontos mit Attributen Kontonummer, Besitzername, Kontostand und Limit
*
* @see "09_Klassen_Aufgaben-1.pdf"
* @author Niklas Buse
*/
public class Account {
private int accountNumber;
private String accountOwner;
private int accountHeight;
private int accountLimit;
/**
* Erstellen eines Kontos
*
* @param accountNumber Kontonummer
* @param accountOwner Kontoinhaber
* @param accountHeight Kontostand
* @param accountLimit Limit
*/
public Account(int accountNumber, String accountOwner, int accountHeight, int accountLimit) {
this.accountNumber = accountNumber;
this.accountOwner = accountOwner;
this.accountHeight = accountHeight;
this.accountLimit = accountLimit;
}
/**
* Rückgabe des Kontowerts
* @return Kontowert
*/
public int getAccountHeight() {
return this.accountHeight;
}
/**
* Ausgabe der Kontoinformationen als String
* @return Kontoinformationen
*/
@Override
public String toString() {
return "Konto Nr. " + this.accountNumber + " (" + this.accountOwner + "), " +
"Stand: " + this.accountHeight + " ct " +
"Limit " + this.accountLimit + " ct";
}
/**
* Erhöhen des Kontostands um den einzuzahlenden Wertes
* @param amount Einzahlungssumme
*/
public void processDeposit(int amount){
this.accountHeight += amount;
}
/**
* Bezahlen einer Summe, solange das Konto inklusive Limit dieses auch zulässt.
* @param amount Zahlungssumme
*/
public void processPayment(int amount){
if(this.accountHeight - amount >= (this.accountLimit*-1)){
this.accountHeight -= amount;
}
else{
System.out.println("\u001B[31mDeckung nicht ausreichend!\u001B[0m"); // Hier wird die Farbe des Roten String direkt in das Ausgeben hinzugefügt.
} // Die Farbinformation wird mit dem Unicode "\u0001B" begonnen und beendet. Die nachstehenden Werte entscheiden die Farbe
}
public static void main(String[] args) {
Account account = new Account(4711, "Donald Duck", 500, 1000);
System.out.println(account);
account.processDeposit(200);
System.out.println(account);
account.processPayment(400);
System.out.println(account);
account.processPayment(2000);
System.out.println(account);
}
}
/* Beispielausführung
--------------------------------------
Eingabe: Keine
--------------------------------------
Ausgabe:
Konto Nr. 4711 (Donald Duck), Stand: 500 ct Limit 1000 ct
Konto Nr. 4711 (Donald Duck), Stand: 700 ct Limit 1000 ct
Konto Nr. 4711 (Donald Duck), Stand: 300 ct Limit 1000 ct
Deckung nicht ausreichend!
Konto Nr. 4711 (Donald Duck), Stand: 300 ct Limit 1000 ct
--------------------------------------
*/