whats the error in here? everytime i run this program even though there are no red underlines and signs still, it say theres an error in here ... and how can i do the same program using if else statement? i have started doing if else but my program its so messy and i dont know what to do :(

package botilparin;

import javax.swing.JOptionPane;

public class New {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		String Deposit ="";
		String Balance = "";
		String password ="";
		String sum ="";
		double ans=0;
		String zz ="pass";
		String aa = "";
		String bb = "";
		String con= "";
		String a = "Y";
		String c = "y";
		String d = "N";
		String e = "n";

		JOptionPane.showMessageDialog(null,"Welcome to ATM!");
		for(int i=0;i<=2;i++){
		password = JOptionPane.showInputDialog(null,"Enter password");
		sum=zz;

		if(password.equals(sum))
		{
		do{
		String choice = JOptionPane.showInputDialog(null,"MainMenu\n1]Balance\n2]Withdraw\n3]Deposit\n4]Exit");
		int sw = Integer.parseInt(choice);

		switch(sw){

		case 1:	
		{
		if(ans < 0){

		JOptionPane.showMessageDialog(null,"Your Current Balance is 0.00");
		}else{
		JOptionPane.showMessageDialog(null,"Your Current Balance is "+ans);
		break;
		}
		}

		case 2:
		{
		aa = JOptionPane.showInputDialog(null,"Withdraw\nEnter amount ");
		int w = Integer.parseInt(aa);

		if(ans < 0 || w >ans ){
		JOptionPane.showMessageDialog(null,"Insufficient Funds!!");
		}else
		ans = ans - w;
		JOptionPane.showMessageDialog(null,"Your Current Balance is "+ans);
		break;
		}

		case 3:
		{
		bb = JOptionPane.showInputDialog(null,"Deposit\nEnter amount ");
		int dep = Integer.parseInt(bb);
		ans = dep + ans;
		JOptionPane.showMessageDialog(null,"Your Current Balance is "+ans);
		break;
		}
		case 4:
		{
		JOptionPane.showMessageDialog(null,"Thank You for using ATM!");
		JOptionPane.showMessageDialog(null,"GOODBYE!!!");
		System.exit(sw);
		}
		default:{
		JOptionPane.showMessageDialog(null,"Invalid Key");
		break;
		}

		}
		con = JOptionPane.showInputDialog(null,"Do You Want Another Transaction?[Y/N]");
		if(con == d || con == e){

		System.exit(0);
		}

		}while(con.equals(a) || con.equals(c));
		break;
		}
		else 
		JOptionPane.showMessageDialog(null,"Invalid Password!!\n Please Try Again!!");
		}
	}

}

this one is my program:

package botilparin;

import javax.swing.JOptionPane;

public class Rosselleatm {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
	
    String a =(JOptionPane.showInputDialog(null, "Automatic Teller Machine\n [B] Balance Inquiry\n [D]Deposit\n [W] Withdrawal\n [Q] Quit\n Select you Options:  ","Automatic Teller Machine",JOptionPane.PLAIN_MESSAGE));
   
   String B= "B";
   String D="D";
   String W="W";
   
   int balance= 0;
   int deposit = 0;
   int withdraw= 0;
   int bal = 0;
   int wht = 0;
int ans = 0;
int trans = 0;
   
   if(a.equalsIgnoreCase(B))
	{
	   JOptionPane.showMessageDialog(null, "Your Balance is: ","BALANCE INQUIRY"+ bal,JOptionPane.PLAIN_MESSAGE );
		
	   
	bal=bal+deposit;
	   ans=JOptionPane.showConfirmDialog(null, "Would you like to generate bank slip?","Generate Bank Slip",JOptionPane.YES_NO_OPTION);
	
		 if (ans == 1);
		{	 //no
	trans =JOptionPane.showConfirmDialog(null,"Would You Like Another Transaction?","Another Transaction",JOptionPane.YES_NO_OPTION);
		
	if (trans == 1)
		
		{
		JOptionPane.showMessageDialog(null, "Thanks For Using My Program!!");
		System.exit(0);
		}

		else if (trans == 0)
		{ 
			 String b =(JOptionPane.showInputDialog(null, "Automatic Teller Machine\n [B] Balance Inquiry\n [D]Deposit\n [W] Withdrawal\n [Q] Quit\n Select you Options:  ","Automatic Teller Machine",JOptionPane.PLAIN_MESSAGE));
		}
		
		
		else if   (ans == 0); // yes
		{	JOptionPane.showMessageDialog(null, "BALANCE INQUIRY \n AMOUNT BALANCE: "+ balance+ "\nPrinting Bank slip.....");
		
		}
		}
		}
		
		
	
	
	
	
   
   
   
   
   
   
 
    else if (a.equalsIgnoreCase(D))
    {
	
	int dep =Integer.parseInt(JOptionPane.showInputDialog (null,"Enter Your Deposit Amount" )); 
	   balance = dep - wht;

	
	
	ans=JOptionPane.showConfirmDialog(null, "Would you like to generate bank slip?","Generate Bank Slip",JOptionPane.YES_NO_OPTION);
	
	if (ans == 1){ //no
JOptionPane.showConfirmDialog(null,"Would You Like Another Transaction?","Another Transaction",JOptionPane.YES_NO_OPTION);
	
   if (trans == 1)
	{
	JOptionPane.showMessageDialog(null, "Thanks For Using My Program!!");
	}
	else if (trans == 0)
	{ 
		 String c =(JOptionPane.showInputDialog(null, "Automatic Teller Machine\n [B] Balance Inquiry\n [D]Deposit\n [W] Withdrawal\n [Q] Quit\n Select you Options:  ","Automatic Teller Machine",JOptionPane.PLAIN_MESSAGE));
	
	}
	
	

	else if (ans == 0)
	{ // yes
		JOptionPane.showMessageDialog(null, "DEPOSIT INQUIRY \n AMOUNT DEPOSIT: "+ dep+ "\nPrinting Bank slip.....");
	}
	
    
	
    else if (a.equalsIgnoreCase(W))
    {
    	 wht= Integer.parseInt(JOptionPane.showInputDialog(null," Enter the Withdrawal Amount:"));
	 
    }
   if (balance <  wht)
   {
	   JOptionPane.showMessageDialog(null, "Insufficient Amount");
   }
   else if (balance >= wht)
   {
	   ans=JOptionPane.showConfirmDialog(null, "Would you like to generate bank slip?","Generate Bank Slip",JOptionPane.YES_NO_OPTION);
   }
		if (ans == 1)
		{ //no
	JOptionPane.showConfirmDialog(null,"Would You Like Another Transaction?","Another Transaction",JOptionPane.YES_NO_OPTION);
		if (trans == 1)
		{
		JOptionPane.showMessageDialog(null, "Thanks For Using My Program!!");
		}
		else if (trans == 0)
		{ 
			 String d =(JOptionPane.showInputDialog(null, "Automatic Teller Machine\n [B] Balance Inquiry\n [D]Deposit\n [W] Withdrawal\n [Q] Quit\n Select you Options:  ","Automatic Teller Machine",JOptionPane.PLAIN_MESSAGE));
		}  
        
		else if (ans == 0)
		{ // yes
		JOptionPane.showMessageDialog(null, "DEPOSIT INQUIRY \n AMOUNT DEPOSIT: "+ withdraw+ "\nPrinting Bank slip.....");
		}
		
		
		}}

thank you i appreciate all the help!

what is the complete error message you get?

there is no particular error, the thing is, my program seems to not be doing the things that i want it to do, for example,
in balance ,

even though i have not deposited anything yet, at least it should show "o.oo" but it dont and on deposit

my problem on Deposit is

when i hit the "yes button" on the question "Would You like to generate slip"
the nest thing it should ask does not show up :(


when i hit the "yes button" on the question "Would You like to generate slip"
the nest thing it should ask does not show up :(

can you give us a complete description of what you are entering each step?
You just said that "the next thing it should ask does not show up". what exactly is the next thing you want to be shown?

this is most likely due to a logical error.. an if-else structure that's a bit off, or a '}' that's placed on a wrong spot.

can you give us a complete description of what you are entering each step?
You just said that "the next thing it should ask does not show up". what exactly is the next thing you want to be shown?

this is most likely due to a logical error.. an if-else structure that's a bit off, or a '}' that's placed on a wrong spot.

yes yes ur right i think } is placed in that wrong place...but i already checked it multiple times..but cant see it..

else if (a.equalsIgnoreCase(D))
    {
	
	int dep =Integer.parseInt(JOptionPane.showInputDialog (null,"Enter Your Deposit Amount" )); 
	
    
	if (ans == 1);
	{	 //no
trans =JOptionPane.showConfirmDialog(null,"Would You Like Another Transaction?","Another Transaction",JOptionPane.YES_NO_OPTION);
	
if (trans == 1)
	
	{
	JOptionPane.showMessageDialog(null, "Thanks For Using My Program!!");
	System.exit(0);
	}

	else if (trans == 0)
	{ 
		 b=(JOptionPane.showInputDialog(null, "Automatic Teller Machine\n [B] Balance Inquiry\n [D]Deposit\n [W] Withdrawal\n [Q] Quit\n Select you Options:  ","Automatic Teller Machine",JOptionPane.PLAIN_MESSAGE));
	}
	
	
	else if   (ans == 0); // yes
	{	JOptionPane.showMessageDialog(null, "BALANCE INQUIRY \n AMOUNT BALANCE: "+ deposit+ "\nPrinting Bank slip.....");
	
	}
	}
	}

there, it should follow that.

when i choose the option deposit i should be able to input number then after that,it will ask me if i want to generate bank slip,

if i say "yes"
Deposit
DEPOSIT AMOUNT: (the deposit thta i have inputted)
Printing Book slip......

if i say no, it will ask me if i want to have another transaction if "yes" it will go back to the main menu, if no it will exit.


but for example.
i deposited 5000
when i do another transaction and choose balance, my balance should be 5000 as well, and when i do another transaction again and choose withdraw and i withdrawed 500
my balance should be 4500


those are the things that i cant do :(

your else if (ans == 0) is placed as a subpart of if ( ans == 1 )
so it will never run.

your if ( ans == 0 ) block only ends at the very end of your code

your else if (ans == 0) is placed as a subpart of if ( ans == 1 )
so it will never run.

your if ( ans == 0 ) block only ends at the very end of your code

so should i put it where? ... :(
im the only one who did not finish this program so i want to learn how things happen here :)

well ...
what you have right now is a structure like this:

boolean b = true;

if ( b == true ){
  performOneAction();
  if ( b == false ){
    performSecondAction();
  }
}

so your second action will never be performed.
you'll need to change that structure, but since I have no idea what your application is supposed to do when it runs correctly, and don't really have the time to figure all of that out, I can't tell you how exactly it should be changed.

well ...
what you have right now is a structure like this:

boolean b = true;

if ( b == true ){
  performOneAction();
  if ( b == false ){
    performSecondAction();
  }
}

so your second action will never be performed.
you'll need to change that structure, but since I have no idea what your application is supposed to do when it runs correctly, and don't really have the time to figure all of that out, I can't tell you how exactly it should be changed.

yes sir its very hard to explain the things that i want to say through this...the main thing here is that i need to make a simple ATM machine

this should have 4 transactions, balance, deposit, withdraw, and quit

when i deposit a certain value, that should come out on balance, and when i withdraw something it should be less on the balance..

Automatic Teller Machine
B Balance
D Deposit
W withdraw
Q quit
select you options:
___________

if i choose balance,

Your Balance is: P0.00(since i havent deposited anything yet)

after that,
*display generate bank slip dialog

Would you like to generate bank slip?(if yes it will print the summary of balnce,

if the answer is no
it will ask:

Would you like another transaction?

if yes, it will go back to the main menu, and if no it will exit, if its for balance, but if it is for withdraw and deposit, it will again ask if i want to generate bank slip

thts how my program should go :)
hope youl never get tired answering my questions

well ... I do understand the general idea, but I don't know what specific steps it has to take for each specific input.

an approach you could do is, for each main function of the application, write a method that performs all the functionality for that partical part of the program.

it would make it a lot easier to test the different subprograms and make it more easier to read the code, since you only have to look at code for a single functionality at the time.

well ... I do understand the general idea, but I don't know what specific steps it has to take for each specific input.

an approach you could do is, for each main function of the application, write a method that performs all the functionality for that partical part of the program.

it would make it a lot easier to test the different subprograms and make it more easier to read the code, since you only have to look at code for a single functionality at the time.

but sir, do u think that my codes have the chance of showing the right output that i want with few revisions?
because im losing hope little by little haha!

I assume that is very well possible, yes, but I think finding the how and where will be a bit more difficult.

but sir, do u think that my codes have the chance of showing the right output that i want with few revisions?
because im losing hope little by little haha!

Reading through this thread, and having seen your past threads, you learnt a lot while writing this program correct? and as you learn you just added, and it happens even to the best of us when something starts going wrong you dont know where to look because you dont understand the main logic of your program and what its busy doing at its different stages and inputs..

I would suggest by instead of revision which you have been trying, why not re-write it, of course using what you've now learnt and of course some copying and pasting of your own code where relevant-not only do i assure you, you will find the error you will write more logical and comprehensible code that you can easily track errors in and your lecturer will understand it and know you do too. This could include adding methods inside the if or case statements to break the code into sections , and have proper error checking etc

Edited 4 Years Ago by DavidKroukamp: n/a

Reading through this thread, and having seen your past threads, you learnt a lot while writing this program correct? and as you learn you just added, and it happens even to the best of us when something starts going wrong you dont know where to look because you dont understand the main logic of your program and what its busy doing at its different stages and inputs..

I would suggest by instead of revision which you have been trying, why not re-write it, of course using what you've now learnt and of course some copying and pasting of your own code where relevant-not only do i assure you, you will find the error you will write more logical and comprehensible code that you can easily track errors in and your lecturer will understand it and know you do too. This could include adding methods inside the if or case statements to break the code into sections , and have proper error checking etc

hey i have re-written my code, and little by little, i can see that now im a bit organized thanks!!! now the codes are working properly thank you!

This question has already been answered. Start a new discussion instead.