99% done but stuck on few things

I'm almost complete but I get an error that initBal is not initialized yet and that it can't find the symbol for newBalance. here is the code and the .java to download. Thanks for any help!

http://www.dangalan.com/java/simulatedBank3.java

import javax.swing.JOptionPane;

publicclass simulatedBank3

{

publicstaticvoid main(String[] args){

double initbal = 0.0;

boolean isMember =false;

int input = 0;

double balance = 0.0;

do{

input = Integer.parseInt(

JOptionPane.showInputDialog(null,

"Enter transaction choice\n1. Open Account\n2. Deposit\n3. Withdrawal\n4. Quit"));

switch (input){

case 1:

input = 1;

isMember =true;

double initBal = Double.parseDouble(

JOptionPane.showInputDialog(null,

"Welcome to Java Bank!\n\n" +

"Enter initial balance."));

while (initBal > 10000)

initBal = Double.parseDouble(

JOptionPane.showInputDialog(null,

"Error! The initial balance must be between $0 and $10,000."));

break;

case 2:

if (isMember){

double depoSI = Double.parseDouble(

JOptionPane.showInputDialog(null,

"Enter amount of deposit:"));

while (depoSI > 10000)

depoSI = Double.parseDouble(

JOptionPane.showInputDialog(null,

"Error! Deposit must be between $0 and $10,000.\nEnter deposit amount:"));

balance = depoSI + initBal;

}else{

JOptionPane.showMessageDialog(null,

"Please open an account first!");

}

break;

case 3:

if (isMember){

double withDraw = Double.parseDouble(

JOptionPane.showInputDialog(null,

"Enter amount of withdrawal:"));

while (withDraw < 0 && withDraw < initBal)

withDraw = Double.parseDouble(

JOptionPane.showInputDialog(null,

"Error! Withdrawal must be between $0 and current balance " + initBal +".\nEnter deposit amount:"));

double newBalance = (balance - withDraw);

}else{

JOptionPane.showMessageDialog(null,

"Please open an account first!");

}

break;

case 4:

input = 4;

JOptionPane.showMessageDialog(null,

"Thank you for your business. Your balance is " + newBalance);

break;

default : JOptionPane.showMessageDialog(null,

"I'm sorry. That is not a valid option.");

break;

}

}while(input < 4);

}

}

[4406 byte] By [intencea] at [2007-11-26 18:47:48]
# 1

> I'm almost complete but I get an error that initBal

> is not initialized yet

You're trying to use initBal when there's a code path that might not have set it.

Example:

int ii;

if (something) {

ii = 1;

}

// What is ii here? If something was false, its valueis undefined

System.out.println(ii);

The solution is for you to figure what your code is supposed to be doing and what initBal should be for every situation where you're using it.

> and that it can't find the

> symbol for newBalance.

You'd have to paste in the exact error message and tell us which line it's occurring on. The basic idea, though, is that you're trying to use a class, method, or variable that doesn't exist, or is out of scope.

jverda at 2007-7-9 6:21:45 > top of Java-index,Java Essentials,Java Programming...
# 2

i think i might of fixed the cannot find symbol for newBalance by putting double newBalance = 0; before the loop. Not sure if that is correct though. Here is the revised code along with some comments.

import javax.swing.JOptionPane;

public class simulatedBank3

{

public static void main(String[] args) {

double initbal = 0.0; //initial balance

boolean isMember = false; //bank member set to false so they must sign up to start

int input = 0; //menu choices

double balance = 0.0;

double newBalance = 0.0;

do {

input = Integer.parseInt( //main menu

JOptionPane.showInputDialog(null,

"Enter transaction choice\n1. Open Account\n2. Deposit\n3. Withdrawal\n4. Quit"));

switch (input){

case 1:

input = 1;

isMember = true; //if a member then user can deposit initial balance

double initBal = Double.parseDouble(

JOptionPane.showInputDialog(null,

"Welcome to Java Bank!\n\n" +

"Enter initial balance."));

while (initBal > 10000)

initBal = Double.parseDouble( //balance must be between $0 and $10,000

JOptionPane.showInputDialog(null,

"Error! The initial balance must be between $0 and $10,000."));

break;

case 2:

if (isMember){ //if member then user able to deposit more money

double depoSI = Double.parseDouble(

JOptionPane.showInputDialog(null,

"Enter amount of deposit:"));

while (depoSI > 10000)

depoSI = Double.parseDouble(

JOptionPane.showInputDialog(null,

"Error! Deposit must be between $0 and $10,000.\nEnter deposit amount:"));

balance = depoSI + initBal; //new balance after deposit

} else {

JOptionPane.showMessageDialog(null,

"Please open an account first!");

}

break;

case 3:

if (isMember){ //if member then user can withdraw money

double withDraw = Double.parseDouble(

JOptionPane.showInputDialog(null,

"Enter amount of withdrawal:"));

while (withDraw < 0 && withDraw < balance) //withdrawal must be between $0 and current balance

withDraw = Double.parseDouble(

JOptionPane.showInputDialog(null,

"Error! Withdrawal must be between $0 and current balance " + initBal + ".\nEnter deposit amount:"));

newBalance = (balance - withDraw);//new balance after withdrawal

}else{

JOptionPane.showMessageDialog(null,

"Please open an account first!");

}

break;

case 4:

input = 4; //when user quits, dialog displays balance

JOptionPane.showMessageDialog(null,

"Thank you for your business. Your balance is " + newBalance);

break;

//if user selects any option other than 1-4, error message appears.

default : JOptionPane.showMessageDialog(null,

"I'm sorry. That is not a valid option.");

break;

}

} while(input < 4);

}

}

intencea at 2007-7-9 6:21:45 > top of Java-index,Java Essentials,Java Programming...