Posted: Thu Oct 25, 2012 7:49 pm Post subject: Java beginner loop questions help!!
2. Write a program to compute the bank balance at the end of each year for 10 years resulting from an initial deposit of $1000 and an annual interest rate of 6%. Output for each year end the number of the year, the initial balance, the interest for the year, and the balance at the end of the year.
Can someone please help me solve this problem? I have tried my best but still cannot get it run properly. This is a Java Eclipse classical 4.2.1. Here is my code:
[img]import javax.swing.JOptionPane;
public class Question2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Your total bank balance for year 2002 is $1060.");
System.out.println("With $1000 original bank balance and 6% interest: $60.");
System.out.println("");
int year;
Double enter, BO=1000.0, IN, BI;
for ( year= 2002; year<2013; year ++)
{
String AS, number;
AS= JOptionPane.showInputDialog("Deposit or withdraw money from your bank account? (Please enter deposit or withdraw only)");
boolean w;{
if (AS.equals("deposit")){
w= true;
}
if (AS.equals("withdraw")){
w= true;
}
else{
System.out.println("Please enter deposit or withdraw only.");
w=false;
}
}
number= JOptionPane.showInputDialog("Please enter the amount of money that you want to deposit or withdraw?");
enter=Double.parseDouble(number);
if (AS=="+"){
BO= BO + enter;
}
if (AS=="-"){
BO= BO - enter;
}
IN= (BO*6)/100;
BI= BO+ IN;
System.out.println("Year " + year);
System.out.println("Total bank balace: $" + BI);
System.out.println("Bank balance with out adding interest: $" + BO);
System.out.println("Total interest (6% interest of the bank balance): $" + IN);
System.out.println("");
}
}
}
[/img]
[/b]
Sponsor Sponsor
Tony
Posted: Thu Oct 25, 2012 9:10 pm Post subject: Re: Java beginner loop questions help!!
ttr @ Thu Oct 25, 2012 7:49 pm wrote:
still cannot get it run properly.
You'd have to be more detailed than that. In what way(s) does it not run properly? What have you already tried to solve those problems?