package j20091203.creditcard;
import java.text.DecimalFormat;
import java.util.Scanner;
public class CreditCard extends Variability {
public AccountInfo accountInfo = new AccountInfo();
Scanner input = new Scanner(System.in);
/**
* 设置数字的小数位为两位
*
* @param rawDouble需要设置的数
* @return已经设置了的数
*/
public double setPrecision(double rawDouble) {
double result;
DecimalFormat df = new DecimalFormat("#0.00");
result = Double.parseDouble(df.format(rawDouble));
return result;
}
/**
* 四舍五入
*
* @param temp
* @return
*/
public double round(double temp) {
int intTemp = (int) temp;
if ((temp - intTemp) > 0.5) {
return intTemp + 1;
} else {
return intTemp;
}
}
/**
* 当前帐户没有可用余额时,透支,判断是否有足够的可用透支金额
*
* @param overDraft透支金额
* @return是否有足够的可用透支金额
*/
public boolean isEnoughWhileNoBalance(double overDraft) {
if ((accountInfo.getOverDraft() - accountInfo.getCurrentOverDraft()) >= overDraft) {
return true;
} else {
return false;
}
}
/**
* 当前帐户有可用余额,但不够取用时,透支多余金额,判断是否有足够的可用透支金额
*
* @param overDraft需要透支的多余金额
* @return是否有足够的可用透支金额
*/
public boolean isEnoughWhilehaveBalance(double overDraft) {
if ((accountInfo.getOverDraft() - accountInfo.getCurrentOverDraft()) >= overDraft) {
return true;
} else {
return false;
}
}
/**
* 取款时,判断当前帐户是否有足够的可用余额
*
* @param getMoney当前想取出的金额
* @return是否有足够的可用余额
*/
public boolean isMoneyEnough(double getMoney) {
if (accountInfo.getAvaiableBalance() >= getMoney) {
return true;
} else {
return false;
}
}
/**
* 还透支款。每还掉100元,“信用额度”和“全部可透支总金额”各增加1点和1元。
*
* @param currentDebt帐户当前透支金额
* @param repayDebt放入用于还款的金额
*/
public void repayOverDraft(double currentDebt, double repayDebt) {
/* 判断当前透支额是否大于放入的还款金额 */
if (currentDebt >= repayDebt) {
/* 放入的还款金额小于或等于当前透支额 */
accountInfo.setCreditStanding(round(accountInfo.getCreditStanding()
+ repayDebt / 100));
accountInfo.setOverDraft(round(accountInfo.getOverDraft()
+ repayDebt / 100));
accountInfo.setCurrentOverDraft(accountInfo.getCurrentOverDraft()
- repayDebt);
if (accountInfo.getCurrentOverDraft() == 0) {// 是否已经还清所有透支款
accountInfo.setIsOverDraft(false);
System.out.println("恭喜,您已经还清所有透支款。帐户当前余额为 "
+ accountInfo.getAvaiableBalance());
}
} else {
/* 放入的还款金额大于当前透支额 */
System.out.println("您放入的还款金额 " + repayDebt + " 大于当前透支额 "
+ accountInfo.getCurrentOverDraft()
+ " 是否要将多余金额存入帐号?按“1”继续还款操作,按“2”返回。");
/* 选择是否将多余金额存入帐户 */
choice = input.nextInt();
if (choice == CONTINUE) {
/* 还款后可存入帐户的金额 */
double avaiableDepositeMoney = repayDebt
- accountInfo.getCurrentOverDraft();
accountInfo.setCreditStanding(round(accountInfo
.getCreditStanding()
+ accountInfo.getCurrentOverDraft() / 100));
accountInfo.setOverDraft(round(accountInfo.getOverDraft()
+ accountInfo.getCurrentOverDraft() / 100));
accountInfo.setIsOverDraft(false);
accountInfo.setCurrentOverDraft(0);
deposite(accountInfo.getAvaiableBalance(),
avaiableDepositeMoney);
System.out.println("恭喜,您已经还清所有透支款。帐户当前余额为 "
+ accountInfo.getAvaiableBalance());
} else if (choice == BACK) {
System.out.println("不继续还款操作,返回。");
}
}
}
/**
* 存款
*
* @param avaiableBalance当前可用余额
* @param depositeMoney要存入的金额
*/
public void deposite(double avaiableBalance, double depositeMoney) {
/* 判断当前是否有透支 */
if (accountInfo.getIsOverDraft()) {
/* 当前有透支,需先还款 */
System.out.println("您当前已经透支 " + accountInfo.getCurrentOverDraft()
+ ",需先还清所有透支款。按“1”继续还款操作,按“2”返回。");
/* 选择是否还款 */
choice = input.nextInt();
if (choice == CONTINUE) {
repayOverDraft(accountInfo.getCurrentOverDraft(), depositeMoney);
if (accountInfo.getIsOverDraft()) {
System.out
.println("您已还掉透支款 "
+ (depositeMoney - accountInfo
.getAvaiableBalance())
+ "目前还有未还透支款 "
+ accountInfo.getCurrentOverDraft());
} else {
System.out.println("恭喜,您已经还清所有透支款。");
}
} else if (choice == BACK) {
System.out.println("不继续还款操作,返回。");
} else {
System.out.println("输入有错,返回。");
}
} else {
/* 当前没有透支,直接存款 */
accountInfo.setAvaiableBalance(setPrecision(avaiableBalance
+ depositeMoney));
accountInfo.setTotalBalance();
System.out.println("您的当前余额为 " + accountInfo.getAvaiableBalance());
}
}
/**
* 取款
*
* @param balance取款前的帐户可用余额
* @param getMoneyAmount本次要取出的金额
*/
public void getMoney(double balance, double getMoneyAmount) {
/* 判断是否有足够余额 */
if (isMoneyEnough(getMoneyAmount)) {
/* 当前有足够可用余额,直接取款 */
accountInfo.setAvaiableBalance(setPrecision(balance
- getMoneyAmount));
accountInfo.setTotalBalance();
System.out.println("当前余额为:" + accountInfo.getAvaiableBalance());
} else {
/* 当前没有足够可用余额,可能进行透支 */
/* 余额不足,需要透支的金额 */
double temp = setPrecision(getMoneyAmount
- accountInfo.getAvaiableBalance());
System.out.println("您的当前余额 " + accountInfo.getAvaiableBalance()
+ " 小于 " + getMoneyAmount + "是否要透支超额的" + temp
+ "?按”1“继续进行操作,按”2“返回。");
/* 选择是否进行透支 */
choice = input.nextInt();
if (choice == CONTINUE) {
/* 判断是否有足够可用透支额 */
if ((accountInfo.getOverDraft() - accountInfo
.getCurrentOverDraft()) >= temp) {
haveBalanceOverDraft(setPrecision(getMoneyAmount - balance));
} else {
System.out.println("您当前可用的透支额小于 " + temp + ",不能透支,返回。");
}
} else if (choice == BACK) {
System.out.println("不继续透支操作,返回。");
} else {
System.out.println("输入有错,返回。");
}
}
}
public void navigate() {// 导航栏
System.out
.println("*****************************************************************************************************************************************************");
System.out
.println("查询--按 1\t\t存款--按 2\t\t取款--按 3\t\t透支--按 4\t\t还透支款--按 5\t\t退出系统--按 0");
}
/**
* 无余额,透支
*
* @param overDraft透支额
*/
public void noBalanceOverDraft(double overDraft) {
/* 判断是否有足够可用透支额 */
if (isEnoughWhileNoBalance(overDraft)) {
accountInfo.setCurrentOverDraft(setPrecision(overDraft
+ accountInfo.getCurrentOverDraft()));
accountInfo.setIsOverDraft(true);
System.out
.println("您的当前透支金额为:" + accountInfo.getCurrentOverDraft());
} else {
System.out.println("可用透支额不足,返回。");
}
}
/**
* 有余额,透支
*
* @param overDraft取完所有余额后,还需要透支的金额
*/
public void haveBalanceOverDraft(double overDraft) {
/* 判断信誉度是否足够 */
if (accountInfo.getCreditStanding() > 0) {
/* 判断是否有足够可用透支额 */
if (isEnoughWhilehaveBalance(overDraft)) {
accountInfo.setCurrentOverDraft(accountInfo
.getCurrentOverDraft()
+ overDraft);
accountInfo.setIsOverDraft(true);
System.out.println("您当前的透支额为: "
+ accountInfo.getCurrentOverDraft());
accountInfo.setAvaiableBalance(0);
accountInfo.setTotalBalance();
} else {
System.out.println("您当前可用的透支额小于 " + ove
评论3
最新资源