mirror of
https://github.com/Dichgrem/Java.git
synced 2025-12-16 20:42:00 -05:00
37 lines
729 B
Java
37 lines
729 B
Java
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;
|
|
}
|
|
}
|