Results 1 to 3 of 3
- 10-28-2011, 04:41 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 1
- Rep Power
- 0
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;
}
}
- 10-28-2011, 04:45 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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]
- 10-28-2011, 04:46 PM #3
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
-
Need help - Here is an assignment I've been working on for two days.
By smileybear33 in forum New To JavaReplies: 10Last Post: 04-19-2011, 03:13 AM -
Been stuck for days! any help would be appriciated...
By juddy1 in forum New To JavaReplies: 8Last Post: 01-06-2011, 06:33 PM -
Game Help.working on it for days,.
By xSkittlesx in forum Java AppletsReplies: 12Last Post: 05-31-2010, 03:24 PM -
Been working on a code for days
By Link01 in forum Java AppletsReplies: 5Last Post: 05-19-2010, 03:55 PM -
No fo days between two dates
By Java Tip in forum Java TipReplies: 0Last Post: 01-28-2008, 09:06 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks