DepositCard.java 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package com.sf.javase.day07.homework;
  2. import java.text.BreakIterator;
  3. /**
  4. * 这是储蓄卡的类
  5. */
  6. public class DepositCard {
  7. private String id;//账户
  8. private Double balance; //余额
  9. public void withdraw(double money){
  10. if(money < 0){
  11. System.out.println("提示取款金额不能为负数");
  12. return;
  13. }
  14. if(money > balance){
  15. System.out.println("否则提示余额不足");
  16. return;
  17. }
  18. balance -= money;
  19. }
  20. public void save(double money){
  21. if(money < 0){
  22. System.out.println("存款不能为负数");
  23. return;
  24. }
  25. balance += money;
  26. }
  27. public String getInfo(){
  28. return "DepositCard{" +
  29. "id='" + id + '\'' +
  30. ", balance=" + balance +
  31. '}';
  32. }
  33. public DepositCard() {
  34. }
  35. public DepositCard(String id, Double balance) {
  36. this.id = id;
  37. this.balance = balance;
  38. }
  39. public String getId() {
  40. return id;
  41. }
  42. public void setId(String id) {
  43. this.id = id;
  44. }
  45. public Double getBalance() {
  46. return balance;
  47. }
  48. public void setBalance(Double balance) {
  49. this.balance = balance;
  50. }
  51. @Override
  52. public String toString() {
  53. return "DepositCard{" +
  54. "id='" + id + '\'' +
  55. ", balance=" + balance +
  56. '}';
  57. }
  58. }