/************************************************************ *Program to calculate how long it will take a bank *balance to reach a certain value, assuming a certain penalty is *charged each week for a negative balance, and the user makes a *certain weekly deposit. User input consists of the current balance, *the desired balance, weekly deposit, and the weekly penalty for negative *balance. * *WARNING: This code has bugs in it! ***********************************************************/ import java.util.Scanner; public class BalanceTrouble { public static void main (String[] args) { Scanner keyboard = new Scanner(System.in); double desiredBalance; double currentBalance, initialBalance; double deposit; double penalty; int countWeeks; System.out.print("\nEnter your current balance: "); initialBalance = keyboard.nextDouble();//Save for later output. currentBalance = initialBalance; System.out.print("\nThe balance you would like to have in your"); System.out.print(" account: "); desiredBalance = keyboard.nextDouble(); System.out.print("\nThe weekly deposit you make: "); deposit = keyboard.nextDouble(); System.out.print("\nWhat penalty does your bank charge "); System.out.print("for a negative balance? "); penalty = keyboard.nextDouble(); countWeeks = 0; //Compute the number of weeks it takes to reach the //desired balance: while (currentBalance < desiredBalance) { if (currentBalance < 0) currentBalance = currentBalance - penalty; countWeeks++; }//while System.out.println("\n\nStarting with an initial balance of $" + initialBalance + ","); System.out.println("With a weekly deposit of $" + deposit); System.out.println("and a penalty of $" + penalty + " for a negative balance,"); System.out.println("you will have a balance of $" + currentBalance); System.out.println("in " + countWeeks + " weeks."); }//main }//BalanceTrouble