-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccount.java
62 lines (58 loc) · 1.43 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
public class Account {
private int id;
private double amount;
private String name;
public Account () {//default construction
/*this.id = 000000;
this.amount= 0.0;
this.name = "No information";*/
this(000000,0.0,"No information-"); //a short cut to create default constructor.
}
public Account (int id,double amount,String name) {
this.id = id;
if (amount >= 0 ) {
this.amount = amount;
}
else {
System.out.println("amount can not be lower than 0. So amount is assigned as 0.0");
}
this.name = name;
}
public void showInf () {
System.out.println(this.id);
System.out.println(this.name);
System.out.println(this.amount+" "+ "$");
}
public void withdraw(double amount) {
if (amount > this.amount)
System.out.println("you can not withdraw an amount that is more than current.");
else if (amount <= this.amount) {
this.amount -= amount;
}
}
public void deposit(double amount) {
if (amount <= 0 )
System.out.println("you can only deposit an amount that is more than 0 $.");
else if (amount > 0) {
this.amount += amount;
}
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}