mirror of
https://github.com/Dichgrem/Java.git
synced 2025-12-16 20:42:00 -05:00
update:demo2
This commit is contained in:
36
com/study/demo2/Account.java
Normal file
36
com/study/demo2/Account.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.study.demo2;
|
||||
|
||||
public class Account {
|
||||
private String accountId;
|
||||
private String owner;
|
||||
private double balance;
|
||||
|
||||
public Account(String accountId, String owner, double balance) {
|
||||
this.accountId = accountId;
|
||||
this.owner = owner;
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
public void deposit(double amount) {
|
||||
if (amount > 0) {
|
||||
balance += amount;
|
||||
}
|
||||
}
|
||||
|
||||
public void withdraw(double amount) {
|
||||
if (amount > 0 && amount <= balance) {
|
||||
balance -= amount;
|
||||
}
|
||||
}
|
||||
|
||||
public void transfer(Account target, double amount) {
|
||||
if (amount > 0 && amount <= balance) {
|
||||
this.balance -= amount;
|
||||
target.balance += amount;
|
||||
}
|
||||
}
|
||||
|
||||
public double getBalance() {
|
||||
return balance;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user