Help - Search - Members - Calendar
Full Version: Java Program Help"nested If Else Statments"
BleepingComputer.com > Software > Programming
   
thagentleman
need help getting nested statements to work. There seems to be a problem with being able to convert the input. I started learning Java 2 days ago so I am a newb but I have programmed in C++ for a couple of years. It says it cannot convert string to booleen. This is also an applet. Please help me.




import javax.swing.JOptionPane; // import class JOptionPane

public class Password
{


public static void main( String args[] )
{
String casino;
Object bet;
String option;
int number1;
int number2;
int number3;
String firstnumber;
String secondnumber;
String thirdnumber;


// read in first number from user as a string
casino = JOptionPane.showInputDialog( "Enter password" );

if
(casino==casino)
{
JOptionPane.showMessageDialog(null,
"Incorrect Password"
);

if(casino.equals(casino))
{
option = JOptionPane.showInputDialog("Enter an Option");
number1 = Integer.parseInt(firstnumber);

if(option=1)
{
JOptionPane.showMessageDialog(null,"You have $500");
}
if(option=2)
{
JOptionPane.showMessageDialog(null, "You have $500, Enter your bet");

}
bet=JOptionPane.showInputDialog(bet);
if(bet<500)

{
JOptionPane.showMessageDialog(null,"Deal cards for Poker");
}
else
JOptionPane.showMessageDialog(null,"You don't have enough money");
}
if(option=3)
{
JOptionPane.showMessageDialog(null,"Thank you for Choosing Java Casino");
}
}
System.exit(0);
}
}
Craigory
First, before anything, I'd recommend reading up on Coding Conventions.

Secondly, it's most of it is because of your operators, you cannot use '=', it must be '==', ex.
if (option = 1) { // WRONG!
if (option == 1) { //CORRECT, in a way, moving on!

Since 'option' is a String, you must parse it, ex.
if (option == 1) { //WRONG!
if (Integer.parseInt(option) == 1) { //CORRECT!

You're last error will be with the 'Object bet', why you're using object is beyond me especially since I don't know anything about poker and what that would be for. But I could guarentee your operator is wrong when you used it aswell, '>'.
groovicus
Craigory, although you are correct in your concepts, your presentation sucks. I suggest first reading the guidelines for posting.

How hard would it be to say "You are using the wrong equalities. "==" is the comparison operator, and "=" is the assignment operator.

And:

"Are you sure you wanted to use Object? What is it that you are trying to accomplish."



******

There.. how does it feel to be derided in public? Maybe next time you could be both helpful and polite. BC strives to be helpful and polite without making others feel badly, and without that elitist attitude.
Craigory
QUOTE(groovicus @ Feb 22 2006, 02:42 PM) *
Craigory, although you are correct in your concepts, your presentation sucks. I suggest first reading the guidelines for posting.

How hard would it be to say "You are using the wrong equalities. "==" is the comparison operator, and "=" is the assignment operator.

And:

"Are you sure you wanted to use Object? What is it that you are trying to accomplish."



******

There.. how does it feel to be derided in public? Maybe next time you could be both helpful and polite. BC strives to be helpful and polite without making others feel badly, and without that elitist attitude.

I don't know why you derided me, I was trying to be helpful, I never intended to make him feel badly at all, I tried to explain it as best as I could and I guess I can agree with you about the object bit, I didn't know what he meant to use it for because I've never played poker.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.