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!