Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package business;
- import java.text.NumberFormat;
- /**
- *
- * @author
- */
- public class PV extends Financial {
- public static final String FUTAMTDESC = "Future Amount";
- public static final String RESULTDESC = "Present Value";
- private boolean built;
- private double[] bbal, iearn, ebal;
- public PV(){
- super();
- this.built = false;
- }
- public PV (double a, double r, int t) {
- super(a,r,t);
- this.built = false;
- if (super.isValid()) {
- buildPV();
- }
- }
- private void biuldPV () {
- try {
- this.bbal = new double[super.getTerm()];
- this.iearn = new double[super.getTerm()];
- this.ebal = new double[super.getTerm()];
- double morate = 0;
- double denom = 0;
- this.bbal[0] = 0;
- for (int i=0; i < super.getTerm(); i++) {
- if (i > 0) {
- this.bbal[i] = this.ebal[i-1];
- }
- morate = super.getRate() / 12.0;
- denom = super.getAmt() /Math.pow((1+morate), super.getTerm());
- this.iearn[i] = (this.bbal[i] + super.getAmt()) * (super.getRate() / 12.0);
- this.ebal[i] = this.bbal[i] + super.getAmt() + this.iearn[i];
- }
- this.built = true;
- } catch (Exception e) {
- super.setErrorMsg("PV build error.");
- this.built = false;
- }
- }
- @Override
- public double getBegBal(int mo) {
- if (!this.built) {
- buildPV();
- if (!this.built) {
- return -1;
- }
- }
- if (mo < 1 || mo > super.getTerm()) {
- return -1;
- }
- return this.bbal[mo-1];
- }
- @Override
- public double getInterest(int mo) {
- if (!this.built) {
- buildPV();
- if (!this.built) {
- return -1;
- }
- }
- if (mo < 1 || mo > super.getTerm()) {
- return -1;
- }
- return this.iearn[mo-1];
- }
- @Override
- public double getPrincipal (int mo) {
- if (!this.built) {
- buildPV();
- if (!this.built) {
- return -1;
- }
- }
- return super.getAmt();
- }
- @Override
- public double getEndBal(int mo){
- if (!this.built) {
- buildPV();
- if (!this.built) {
- return -1;
- }
- }
- if (mo < 1 || mo > super.getTerm()) {
- return -1;
- }
- return this.ebal[mo-1];
- }
- @Override
- public double getResult() {
- if (!this.built) {
- buildPV();
- if (!this.built) {
- return -1;
- }
- }
- return this.ebal[super.getTerm()-1];
- }
- @Override
- public String getTitle () {
- NumberFormat curr = NumberFormat.getCurrencyInstance();
- NumberFormat pct = NumberFormat.getPercentInstance();
- pct.setMaximumFractionDigits(3);
- return "Annuity Schedule " + curr.format(super.getAmt()) + " per month @ " + pct.format(super.getRate()) + " for " + super.getTerm() + " months.";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement