简体   繁体   English

为一个简单的信用卡账户编写一个类

[英]Write a class for a simple credit card account

A credit account has a description, principal balance, an APR, a minimum monthly payment percentage (usually between 1% and 3%) and a minimum monthly payment amount.In addition to the constructor, setters, getters, and toString methods, add methods to make a purchase using the credit card (increasing the principal by a certain amount), make a payment on the card (decrease the principle by a certain amount), calculate the monthly interest amount (principal balance * APR/12), and calculate the minimum monthly payment (principal balance * minimum monthly payment rate or the minimum monthly payment amount, whichever is greater, or the principle balance if it is lower than the calculated minimum payment amount).信用账户有描述、本金余额、APR、最低月还款百分比(通常在 1% 到 3% 之间)和最低月还款金额。 除了构造函数、setter、getter 和 toString 方法外,添加方法使用信用卡购买(增加一定金额的本金),在卡上付款(减少一定金额的本金),计算每月的利息金额(本金余额* APR / 12),并计算每月最低还款额(本金余额*每月最低还款率或每月最低还款额,以较大者为准,或低于计算出的最低还款额则为本金余额)。 Hint: If storing the rates as percentages, remember to divide by 100 to get the decimal value (ex. 2% means to multiply by .02).提示:如果将比率存储为百分比,请记住除以 100 以获得十进制值(例如 2% 表示乘以 0.02)。

Since most people have multiple credit cards, use this class to write an application to maintain a list of credit cards (create an array of credit card objects), and present the user with the principal, interest, and minimum payment amount for the month for each card in the list.由于大多数人拥有多张信用卡,因此使用该类编写一个应用程序来维护信用卡列表(创建信用卡对象数组),并向用户显示当月的本金、利息和最低还款额列表中的每张卡片。

Add a method to the credit card class to calculate the number of months it would take to pay off the card (get to a balance of zero) if only the minimum monthly payment was paid each month.向信用卡类添加一个方法,以计算如果每月只支付最低月供,还清卡所需的月数(余额为零)。 Remember that this method should not change the current information for the card in any way, it is just a calculation.请记住,此方法不应以任何方式更改卡的当前信息,它只是一种计算。

This is what I have so far:这是我到目前为止:

public class CreditCardDebt {
  //Instance Variables 
  private String cardName;
  private double princBal;
  private double aPR;
  private double monthPayPercent;
  private double monthPayAmount;

  //Constructor 
  public CreditCardDebt(String name, double origBal, double apr, double     mnthPercent, double mnthAmount) {
    cardName = name;
    princBal = origBal;
    aPR = apr;
    monthPayPercent = mnthPercent;
    monthPayAmount = mnthAmount;
  }

  //Mutator/Setter
  public void cardName(String name){
    cardName = name;
  }
  public void princBal(double origBal){
    princBal = origBal;
  }
  public void aPR(double apr){
    aPR = apr;
  }
  public void monthPayPercent(double mnthPercent){
    monthPayPercent = mnthPercent;
  }
  public void monthPayAmount(double mnthAmount){
    monthPayAmount = mnthAmount;
  }

  //Accessor/Getter
  public String getCardName () {
    return cardName; 
  }
  public double getPrincBal () {
    return princBal;
  }
  public double getAPR () {
    return aPR; 
  }
  public double getMonthPayPercent () {
    return monthPayPercent;
  }
  public double getMonthPayAmount () {
    return monthPayAmount; 
  }

  //Other Methods
  public double addPurchase () {
    return princBal+;
  }
  public double makePay () {
    return -princBal;
  }
  public double calcMonthInterestAmnt () {
    return princBal*(aPR/12);
  }
  public doublt calcMinMonthPay () {
    return princBal * 



  //toString
  public String toString () {
    return "Card: " + cardName + " has a principle balance of: " 
      + princBal + ", an APR of " + aPR + 
      ", a minimum monthly payment percentage of " + monthPayPercent + 
      ", and a minimum monthly payment amount of " + monthPayAmount + ".";
  }
}

I know I'm missing a lot.. Please help.我知道我错过了很多……请帮忙。

The description you have given is basically check-list of functionality that needs to be implemented.您给出的描述基本上是需要实现的功能的清单。

My suggestion is to break each task down into smaller and smaller bits and that you can work your way through and check of as you do them.我的建议是将每项任务分解成越来越小的部分,这样你就可以一边做一边检查。 This will give you a nice roadmap, and also give you good feels as you check of each task, which will provide you with much needed encouragement.这将为您提供一个很好的路线图,并且在您检查每项任务时也会给您良好的感觉,这将为您提供急需的鼓励。

If a task is too much, try to break it down into smaller tasks that you can easily check off.如果一个任务太多,试着把它分解成更小的任务,你可以很容易地核对。

The description is pretty much already in the order that the code needs to be written in, so just work your way through the list.描述几乎已经按照代码需要编写的顺序进行了,所以只需按照您的方式完成列表即可。

If you run into a specific problem that you are struggling to solve, post a new question on Stack Overflow that follows the How to ask a good question guide如果您遇到一个您正在努力解决的特定问题,请在 Stack Overflow 上发布一个新问题,该问题遵循如何提出一个好的问题指南

Here is the description broken up into separate reasonably manageable tasks:以下是分解为单独的合理可管理任务的描述:

  • Create a credit account class that has the following properties:创建具有以下属性的信用帐户类:
    • a description说明
    • principal balance,本金余额,
    • an APR APR
    • a minimum monthly payment percentage (usually between 1% and 3%)最低每月付款百分比(通常在 1% 到 3% 之间)
    • a minimum monthly payment amount每月最低还款额
  • Has a constructor有一个构造函数
    • Set each property to their initial values将每个属性设置为其初始值
  • Has getters and setters for each property每个属性都有 getter 和 setter
  • Has a toString method有一个toString方法
  • Has a method to make a purchase有购买方法
    • increases the principal by a certain amount增加一定数量的本金
  • Has a method to make a payment有付款方式
    • decrease the principle by a certain amount减少一定数量的原则
  • Has a method to calculate the monthly interest amount有计算每月利息金额的方法
    • principal balance * APR/12本金余额 * APR/12
  • Has a method to calculate the minimum monthly payment有一种计算每月最低还款额的方法
    • principal balance * minimum monthly payment rate or, the minimum monthly payment amount, whichever is greater or the principle balance if it is lower than the calculated minimum payment amount本金余额 * 每月最低还款率或每月最低还款额,以较大者为准,或本金余额低于计算出的最低还款额
    • Hint: If storing the rates as percentages, remember to divide by 100 to get the decimal value (ex. 2% means to multiply by .02).提示:如果将比率存储为百分比,请记住除以 100 以获得十进制值(例如 2% 表示乘以 0.02)。
  • Create an application that maintain a list of credit cards创建一个维护信用卡列表的应用程序
    • create an array of credit card objects创建信用卡对象数组
  • for each card in the list对于列表中的每张卡片
    • present the user with the principal, interest, and minimum payment amount for the month.向用户显示当月的本金、利息和最低还款额。
  • Add a method to the credit card class to calculate the number of months it would take to pay off the card向信用卡类添加一个方法来计算还清信用卡所需的月数
    • if only the minimum monthly payment was paid each month.如果每月只支付最低月供。
    • Remember that this method should not change the current information for the card in any way, it is just a calculation.请记住,此方法不应以任何方式更改卡的当前信息,它只是一种计算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM