This site requires JavaScript, please enable it in your browser!
Greenfoot back
Green_footlong_subway
Green_footlong_subway wrote ...

2014/2/27

Struggling with a my program can some one help me!!

I have worked the the password issue but I want the program to recognize if the user has said Return or single and then deduct it from his credit, is there anyway that some one can help me, thank you. GreenfootImage textImage1 = new GreenfootImage("PAY FOR TICKET HERE",25, Color.BLACK, Color.WHITE); setImage(textImage1); String password="busman"; String passcode=password; String code=password; int credit=30; int Return=5; int Single=3; if(Greenfoot.mouseClicked(this)) { String Passcode = JOptionPane.showInputDialog("what is your password"); if(password==password) { System.out.println("accepted"); } } if(Greenfoot.mouseClicked(this)) { String rors = JOptionPane.showInputDialog("Return or Single"); if (rors==""+Return) { System.out.println(credit-Return ); } }
davmac davmac

2014/2/27

#
Please use code tags when you post here. You have at least the following problems:
 String Passcode = JOptionPane.showInputDialog("what is your password");
Variables in Java should start with a lower-case letter, so "Passcode" should be "passcode" or something similar.
 if(password==password)
Here you are checking if a reference variable is equal to itself, which will always be true.
You need to login to post a reply.