12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package com.sf.homework;
- import java.text.BreakIterator;
- /**
- * (2)声明一个银行信用卡CreditCard类,继承储蓄卡类
- * 增加属性:本月可透支总额度,本月已透支金额
- * 重写public void withdraw(double money),可透支,
- * 取款金额超过账户余额+本月还可透支额度,提示超过可透支额度
- * 取款金额在账户余额范围内,不用透支
- * 取款金额超过账户余额但在可透支范围内,需要透支
- * 重写public void save(double money),
- * 存款金额不能为负数,否则提示存款金额不能为负数
- * 本次存款金额只够偿还部分已透支金额
- * 本次存款金额除了偿还透支金额,还有剩余
- * (3)在测试类中,分别创建两种卡对象,测试
- */
- /**
- * 储蓄卡类
- */
- public class DepositCard {
- private String id; //代表的是账户信息id
- private double balance; //代表的是余额
- public String getId(){
- return id;
- }
- public void setId(String id){
- this.id = id;
- }
- public double getBalance(){
- return balance;
- }
- public void setBalance(double balance){
- this.balance = balance;
- }
- /**
- * 取款方法
- * @param money
- */
- public void withdraw(double money){
- if(money < 0){
- System.out.println("取款金额不能为负数!!!");
- }
- if(money > balance){
- System.out.println("余额不足!!!");
- }
- //取钱
- balance -= money;
- }
- /**
- * 存款方法
- * @param money
- */
- public void save(double money){
- if(money < 0){
- System.out.println("存款金额不能为负数");
- }
- balance += money;
- }
- /**
- * 可以返回账户和余额
- * @return
- */
- public String getInfo(){
- return "账户:"+id+" , 余额:"+balance;
- }
- }
|