jerelp
07-13-2011, 01:44 AM
Hello,
I just want to know if I'm on the right track with this program. I can't seem to grasp if i'm using the correct loop or not.
The assignment is:
Bank Balance **:
The First National Bank of Parkville recently opened up a new “So You Want to Be a Millionaire” savings account. The new account works as follows:
• The bank doubles the customer’s balance every year until the customer’s balance reaches one million.
• The customer isn’t allowed to touch the money (no deposits or withdrawals) until the customer’s balance reaches one million.
• If the customer dies before becoming a millionaire, the bank keeps the customer’s balance.
• Note: Customers close to $1,000,000 tend to get “accidentally” run over in the bank’s parking lot.
Write a program that prompts the user for a starting balance and then prints the number of years it takes to reach $100,000 and also the number of years it takes to reach $1,000,000.
Sample session:
Enter starting balance: 10000
It takes 4 years to reach $100,000.
It takes 7 years to reach $1,000,000.
This is the code I have so far. I'm only doing for 100,000 and seeing if that works first before I move on to the next 1,000,000. any help would be great. Thank you for your time.
/****************************************************
* Bank.java
* Jerel Paule
* 07-06-2011
* This Program Calculates the area, diameter, and
* Circumfrence from the radius
****************************************************/
import java.util.Scanner;
public class Bank
{
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
//Variables
int balance; // starting balance
int i = 0;
// int j = 0;
do
{
System.out.print("Please enter starting balance: ");
balance = stdIn.nextInt();
i ++;
if (balance < 1000000)
{
balance = balance * 2;
}
} while (balance <= 100000);
System.out.println("It takes "+ i + " years to reach $100,000.");
}
}
I just want to know if I'm on the right track with this program. I can't seem to grasp if i'm using the correct loop or not.
The assignment is:
Bank Balance **:
The First National Bank of Parkville recently opened up a new “So You Want to Be a Millionaire” savings account. The new account works as follows:
• The bank doubles the customer’s balance every year until the customer’s balance reaches one million.
• The customer isn’t allowed to touch the money (no deposits or withdrawals) until the customer’s balance reaches one million.
• If the customer dies before becoming a millionaire, the bank keeps the customer’s balance.
• Note: Customers close to $1,000,000 tend to get “accidentally” run over in the bank’s parking lot.
Write a program that prompts the user for a starting balance and then prints the number of years it takes to reach $100,000 and also the number of years it takes to reach $1,000,000.
Sample session:
Enter starting balance: 10000
It takes 4 years to reach $100,000.
It takes 7 years to reach $1,000,000.
This is the code I have so far. I'm only doing for 100,000 and seeing if that works first before I move on to the next 1,000,000. any help would be great. Thank you for your time.
/****************************************************
* Bank.java
* Jerel Paule
* 07-06-2011
* This Program Calculates the area, diameter, and
* Circumfrence from the radius
****************************************************/
import java.util.Scanner;
public class Bank
{
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
//Variables
int balance; // starting balance
int i = 0;
// int j = 0;
do
{
System.out.print("Please enter starting balance: ");
balance = stdIn.nextInt();
i ++;
if (balance < 1000000)
{
balance = balance * 2;
}
} while (balance <= 100000);
System.out.println("It takes "+ i + " years to reach $100,000.");
}
}