所以这个项目是在我的舒适区之外。我会将我目前的发展阶段描述为:“我知道诸如:收藏,设计模式,以及通常为什么会产生良好的面向对象的原因。但是这些东西有点像我目前的极限。因此,我可能不会使用它们或试图尽可能多地使用它们。“爪哇:面向对象的建议和建议,以推进一个小应用程序
我试图改变这种状况,所以我一直在努力研究相当小的挑战/应用程序,它真的适合于上面并要求自己写出聪明,干净的代码。我对迄今为止能够做到的事情非常满意。但是,我还剩下两门课,但仍需要深入研究。我对如何解决这个问题有很多想法。我敢肯定,有些是好的,有些是坏的,但更重要的是,我认为我在思考问题。
总之,这里是我想要做的,这里是我,这里是我需要的地方:
我想要做的事:最简单说明这个应用的目标的方式是,我有信用卡(这个班是我所做的班),我有钱包,我有人。从高级角度来看,我把卡片放在人们的钱包和钱包里。我有3张牌,他们的名字和利率真的不同。我想要一些钱包有一张卡,其他人有三张。至于钱包,每个人至少需要一个,但我想给两个人。这确实是关于它的,我计算了一些简单的兴趣数学,我将在某些时候配合使用,但大多数情况下我都希望构建一个干净和设计良好的应用程序。
我有什么:正如我所说我或多或少有CreditCard
类完成。我仍然在很好地调整它,但我已经能够改善它很多,我对它随随便便。我将在下面包括这个类来为应用程序提供上下文,因此如果需要,您可以提供建议。在课程的顶部你会看到很多文档。这主要是数学,而这是逻辑,用于计算简单的兴趣。你会看到的。但是我也有两个我正在编码的测试用例,你也会看到。
我需要去的地方:那么我有信用卡。现在我只需要钱包和人。从我的角度来看,我可以看到使用ArrayList的钱包。尽管如此,收藏的不同方面可能会更好。我主要(主要)使用ArrayList,所以我主要使用ArrayList。到目前为止,这是成功的...除此之外,我一直在考虑制作电子钱包和人物摘要,这似乎是一个好主意,但再次,没有太多经验做出这些选择。因此,在所有这一切的结尾,我正在寻找一些方向,确定好的想法和替代较弱的想法。如果这些可以与示例相结合,或者如果建议可以用言语和代码表达自己,这将是最佳的,因为当我看到它在行动中时,我得到更多的建议。对于我来说,一个好的代码建议,通常比没有的建议更有帮助。这完全是关于能够应用该建议。但是,那只是我,每个人都不一样。我可以告诉你的是,这是明确的,就是所有的建议,无论它们是什么,都会受到赞赏和帮助。因为,我正在这样做,我在这里,要学习。
/*
* Test Cases:
* 1) 1 person has 1 wallet and 3 cards (1 Visa, 1 MC 1 Discover) – Each Card has a balance of $100 – calculate the total interest (simple interest) for this person and per card.
*
* 2) 1 person has 2 wallets Wallet 1 has a Visa and Discover , wallet 2 a MC - each card has $100
* balance - calculate the total interest(simple interest) for this person and interest per wallet
*/
/*
* Formula Key:
*
* Algebraic Symbols:
* A = Total Accrued Amount (principal + interest)
* P = Principal Amount
* I = Interest Amount
* r & R = Rate of Interest per year in percentage & decimal
* t = Time Period involved in months or years(duration pertaining to this equation)
*
* Rate of Interest, Percentage To Decimal Equations:
* R = r * 100
* r = R/100
*
* Simple Interest Equation:
* A = P(1 + (r * t))
*/
/*
* Card:
* VISA 10%
*
* Equation:
* Accrued Amount(A) = Principle Amount(P) * (1 +(Interest Rate(r) * Time Period(t)))
*
* Calculation:
* First, converting Interest Rate(R) of 10%, to, Interest Rate(r) of 0.1
* r = R/100 = 10%/100 = 0.1 per year,
* put Time Period(t) of 1 month into years,
* months/year(1 month ÷ 12) = 0.08 years
*
* Solving Equation:
* A = 100(1 + (0.1 × 0.08)) = 100.8
* A = $ 100.80
*
* Solution:
* The total Amount Accrued(A), Principal(P) plus Interest(I),
* from Simple Interest on a Principal(P) of $ 100.00
* at a Rate(r = R/100(convert a percentage to a decimal)) of 10% or 0.1 per year
* for 0.08 years, 1 month(t) is $ 100.80.
*/
/*
* Card:
* MC(Master Card) 5%
*
* Equation:
* Accrued Amount(A) = Principle Amount(P) * (1 +(Interest Rate(r) * Time Period(t)))
*
* Calculation:
* First, converting Interest Rate(R) of 5%, to, Interest Rate(r) of 0.05
* r = R/100 = 5%/100 = 0.05 per year,
* put Time Period(t) of 1 month into years,
* months/year(1 month ÷ 12) = 0.08 years
*
* Solving Equation:
* A = 100(1 + (0.05 × 0.08)) = 100.4
* A = $ 100.40
*
* Solution:
* The total Amount Accrued(A), Principal(P) plus Interest(I),
* from Simple Interest on a Principal(P) of $ 100.00
* at a Rate(r = R/100(convert a percentage to a decimal)) of 5% or 0.05 per year
* for 0.08 years, 1 month(t) is $ 100.40.
*/
/*
* Card:
* Discover 1%
*
* Equation:
* Accrued Amount(A) = Principle Amount(P) * (1 +(Interest Rate(r) * Time Period(t)))
*
* Calculation:
* First, converting Interest Rate(R) of 1%, to, Interest Rate(r) of 0.01
* r = R/100 = 1%/100 = 0.01 per year,
* put Time Period(t) into years,
* months/year(1 month ÷ 12) = 0.08 years
*
*
* Solving Equation:
* A = 100(1 + (0.01 × 0.08)) = 100.08
* A = $ 100.08
*
* Solution:
* The total Amount Accrued(A), Principal(P) Plus Interest(I),
* from Simple Interest on a Principal(P) of $ 100.00
* at a Rate(r = R/100(convert a percentage to a decimal)) of 1% or 0.01 per year
* for 0.08 years, 1 month(t) is $ 100.08.
*/
public class CreditCard
{
private BrandOfCard brandOfCard;
private static final double PRINCIPAL_AMOUNT = 100.00;
private static final double TIME_PERIOD = 0.08;
public CreditCard(BrandOfCard brandOfCard)
{
this.brandOfCard = brandOfCard;
}
/*
* A = P(1 + (r * t))
*/
public double getAccruedAmount()
{
double accruedAmount;
accruedAmount = PRINCIPAL_AMOUNT * (1 + (brandOfCard.getInterestRate() * TIME_PERIOD));
return accruedAmount;
}
public enum BrandOfCard
{
VISA(0.1), MASTER_CARD(0.05), DISCOVER(0.01);
private final double interestRate;
BrandOfCard(double interestRate)
{
this.interestRate = interestRate;
}
public double getInterestRate()
{
return interestRate;
}
}
//bottom of class
public static void main(String[] args)
{
CreditCard visa = new CreditCard(BrandOfCard.VISA);
CreditCard masterCard = new CreditCard(BrandOfCard.MASTER_CARD);
CreditCard discover = new CreditCard(BrandOfCard.DISCOVER);
double accruedAmount;
accruedAmount = visa.getAccruedAmount();
System.out.println("Visa card, with a principle amount of $100.00, & an interest rate of 10%, " +
"has accrued $" + (accruedAmount - PRINCIPAL_AMOUNT) + " in interest, " +
"over the last monthly term.");
System.out.println("The total amount due on this card is now $" + accruedAmount);
accruedAmount = masterCard.getAccruedAmount();
System.out.println("Master Card card, with a principle amount of $100.00, & an interest rate of 5%, " +
"has accrued $" + (accruedAmount - PRINCIPAL_AMOUNT) + " in interest, " +
"over the last monthly term.");
System.out.println("The total amount due on this card is now $" + accruedAmount);
accruedAmount = discover.getAccruedAmount();
System.out.println("Discover card, with a principle amount of $100.00, & an interest rate of 1%, " +
"has accrued $" + (accruedAmount - PRINCIPAL_AMOUNT) + " in interest, " +
"over the last monthly term.");
System.out.println("The total amount due on this card is now $" + accruedAmount);
}
}
W¯¯帽子是'钱包'的用途? – 2015-02-08 00:53:38
好吧,我想首先,对我来说,这似乎是有道理的,“试图让你的代码更好地代表生活世界的方式。”因此,我开始试图确定一个钱包为什么有用以及它真正做了什么。为了将其降低到更多的代码级别,我会说钱包拥有一组类似的对象,在这种情况下是卡片。如果一个人有两个钱包,那么这些钱包就会存放物品,并在两组之间提供分离/区别。这就是我想在我的钱包中实现的。 – ReedWilliams19842004 2015-02-08 01:11:15
虽然这是事实,但OOP的目标不是在您的设计中实现所有可能的类,而只是那些影响功能的类。卡的余额,利息等将如何取决于它保存的特定钱包? – 2015-02-08 01:22:31