Results 1 to 3 of 3
  1. #1
    ajimda is offline Member
    Join Date
    Oct 2011
    Posts
    1
    Rep Power
    0

    Default Help, I have been working on this for days

    I 'm new to java and taking a class. I have a problem for a savings account that adds deposits, withdrawals, calculates interest etc. I cannot get the monthlyInterestEarnedTotal to return. I had it working, but then it didn't. Can anyone tell me why and what I am doing wrong. Thank you..


    public class SavingsAccountMain {

    public static void main(String[] args) {

    Scanner keyboard = new Scanner(System.in);

    NumberFormat currency = NumberFormat.getCurrencyInstance();

    double annualInterestRate = 0;
    double beginningBalance;
    double calcEndingBalance;


    System.out.println("Enter the beginning balance amount of "
    + "your account: ");
    beginningBalance = keyboard.nextDouble();

    System.out.println("Enter the enter the annual interest you receive"
    + " on this this Account: ");
    annualInterestRate = keyboard.nextDouble();

    while (annualInterestRate < 0 || annualInterestRate > 1) {

    System.out.println("Your number is Invalid.");
    System.out.println("You must enter a positive deminal i.e. 5% = .05 ");
    annualInterestRate = keyboard.nextDouble();
    }


    SavingsAccount money = new SavingsAccount(beginningBalance);

    money.getCalcEndingBalance();


    System.out.println("Your beginning balance was: " + currency.format(beginningBalance));

    System.out.println("Your total withdrawals were: " + currency.format(money.getWithdrawalTotal()));

    System.out.println("Your total deposits were: " + currency.format(money.getDepositTotal()));

    System.out.println("Your total interest earned was: " + currency.format(money.getMonthlyInterestEarnedTota l()));

    System.out.println("Your ending balance is: " + currency.format(money.getEndingBalance()));

    }
    }

    --------------------------------------------

    import java.util.Scanner;
    import java.text.NumberFormat;

    /
    public class SavingsAccount {

    Scanner keyboard = new Scanner(System.in);
    private double beginningBalance ;
    private double endingBalance;
    private double annualInterestRate = 0;
    private double monthlyInterestRate = 0;
    public double monthlyInterestEarnedTotal = 0;
    private double withdrawal = 0;
    private double withdrawalTotal = 0;
    private double deposit = 0;
    private double depositTotal = 0;
    private double monthlyInterestEarned =0 ;
    private int numberOfMonths;
    private int count = 1;
    private double calcEndingBalance;

    NumberFormat currency = NumberFormat.getCurrencyInstance();

    public double getCalcEndingBalance() {
    return calcEndingBalance;
    }

    public void setCalcEndingBalance(double calcEndingBalance) {
    this.calcEndingBalance = calcEndingBalance;
    }

    public SavingsAccount(double beginningBalance) {
    this.beginningBalance = beginningBalance;
    calcEndingBalance();

    }

    public double getAnnualInterestRate() {
    return annualInterestRate;
    }

    public void setAnnualInterestRate(double annualInterestRate) {
    this.annualInterestRate = annualInterestRate;
    }

    public double getBeginningBalance() {
    return beginningBalance;
    }

    public void setBeginningBalance(double beginningBalance) {
    this.beginningBalance = beginningBalance;
    }

    public double getDeposit() {
    return deposit;
    }

    public void setDeposit(double deposit) {
    this.deposit = deposit;
    }

    public double getMonthlyInterestEarned() {
    return monthlyInterestEarned;
    }

    public void setMonthlyInterestEarned(double monthlyInterestEarned) {
    this.monthlyInterestEarned = monthlyInterestEarned;
    }

    public double getMonthlyInterestRate() {
    return monthlyInterestRate;
    }

    public void setMonthlyInterestRate(double monthlyInterestRate) {
    this.monthlyInterestRate = monthlyInterestRate;
    }

    public int getNumberOfMonths() {
    return numberOfMonths;
    }

    public void setNumberOfMonths(int numberOfMonths) {
    this.numberOfMonths = numberOfMonths;
    }

    public double getWithdrawal() {
    return withdrawal;
    }

    public void setWithdrawal(double withdrawal) {
    this.withdrawal = withdrawal;
    }

    public double getDepositTotal() {
    return depositTotal;
    }

    public void setDepositTotal(double depositTotal) {
    this.depositTotal = depositTotal;
    }

    public double getEndingBalance() {
    return endingBalance;
    }

    public void setEndingBalance(double endingBalance) {
    this.endingBalance = endingBalance;
    }

    public double getMonthlyInterestEarnedTotal() {
    return monthlyInterestEarnedTotal;
    }

    public void setMonthlyInterestEarnedTotal(double monthlyInterestEarnedTotal) {
    this.monthlyInterestEarnedTotal = monthlyInterestEarnedTotal;
    }

    public double getWithdrawalTotal() {
    return withdrawalTotal;
    }

    public void setWithdrawalTotal(double withdrawalTotal) {
    this.withdrawalTotal = withdrawalTotal;
    }

    public double calcEndingBalance() {

    System.out.println("Enter the number of months since the account "
    + "was openned: ");
    numberOfMonths = keyboard.nextInt();


    endingBalance = beginningBalance;


    monthlyInterestRate = annualInterestRate / 12;

    do {

    System.out.println("What is the amount that withdrawn in month "
    + "number " + count + ": ");
    withdrawal = keyboard.nextDouble();


    System.out.println("What is the amount that you deposited in month "
    + "number " + count + ": ");
    deposit = keyboard.nextDouble();


    endingBalance = endingBalance + deposit - withdrawal;

    monthlyInterestEarned = endingBalance * monthlyInterestRate;

    endingBalance = endingBalance + monthlyInterestEarned;

    withdrawalTotal -= withdrawal;

    depositTotal += deposit;

    monthlyInterestEarnedTotal += monthlyInterestEarned;

    count++;

    } while (count <= numberOfMonths);


    return calcEndingBalance;

    }
    }

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: Help, I have been working on this for days

    Edit your post and add code tags to your code. [code] YOUR CODE HERE [/code]

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,889
    Rep Power
    8

    Default Re: Help, I have been working on this for days

    When do you return it?

    If you want help, you should provide an SSCCE that eliminates all the extra stuff and only demonstrates the problem. Also, don't forget the code tags.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 10
    Last Post: 04-19-2011, 03:13 AM
  2. Replies: 8
    Last Post: 01-06-2011, 06:33 PM
  3. Game Help.working on it for days,.
    By xSkittlesx in forum Java Applets
    Replies: 12
    Last Post: 05-31-2010, 03:24 PM
  4. Been working on a code for days
    By Link01 in forum Java Applets
    Replies: 5
    Last Post: 05-19-2010, 03:55 PM
  5. No fo days between two dates
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-28-2008, 09:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •