Account
unknown
java
3 years ago
2.8 kB
8
Indexable
public class Account { private String soTaiKhoan; private String tenTaiKhoan; public long soTien; // Hằng số private final double laiSuat = 0.5f * 0.1f; // 0.1 là 100% => 0.5% là 0.05 private final int phiRutTien = 5000; public Account() { } public Account(String soTaiKhoan, String tenTaiKhoan, long soTien) { this.soTaiKhoan = soTaiKhoan; this.tenTaiKhoan = tenTaiKhoan; this.soTien = soTien; } public String getSoTaiKhoan() { return soTaiKhoan; } public void setSoTaiKhoan(String soTaiKhoan) { this.soTaiKhoan = soTaiKhoan; } public String getTenTaiKhoan() { return tenTaiKhoan; } public void setTenTaiKhoan(String tenTaiKhoan) { this.tenTaiKhoan = tenTaiKhoan; } // Phương thức nạp tiền public boolean napTien(long soTienNap) { if (soTienNap > 0) { this.soTien += soTienNap; System.out.println("Tài khoản: " + this.soTaiKhoan + " Nạp thành công!\nSố tiền hiện tại trong tài khoản là: " + this.soTien); return true; } else { System.out.println("Tài khoản: " + this.soTaiKhoan + " Nạp thất bại!\nSố tiền nạp không hợp lệ"); return false; } } // Phương thức rút tiền public boolean rutTien(long soTienRut) { long tongTienPhaiTru = soTienRut + phiRutTien; if (this.soTien < tongTienPhaiTru) { System.out.println("Tài khoản: " + this.soTaiKhoan + " Rút thất bại!\nSố tiền rút quá lớn."); return false; } else { this.soTien -= tongTienPhaiTru; System.out.println("Tài khoản: " + this.soTaiKhoan + " Rút thành công!\nTài khoản còn: " + this.soTien); return true; } } // Phương thức đáo hạn public void daoHan() { this.soTien += this.soTien * laiSuat; System.out.println("Tài khoản: " + this.soTaiKhoan + " Đáo hạn thành công!\nSố tiền hiện tại là: " + this.soTien); } // Phương thức chuyển khoản public boolean chuyenKhoan(Account accountB, long soTienChuyen) { if (soTienChuyen > this.soTien) { System.out.println("Chuyển khoản thất bại! Số tiền cần chuyển quá lớn"); return false; } else { accountB.soTien += soTienChuyen; this.soTien -= soTienChuyen; System.out.println("Chuyển tiền thành công!"); System.out.println("Tài khoản: " + this.soTaiKhoan + " còn: " + this.soTien); System.out.println("Tài khoản: " + accountB.soTaiKhoan + " có: " + accountB.soTien); return true; } } }
Editor is loading...