Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Java Program Help"nested If Else Statments"


  • Please log in to reply
3 replies to this topic

#1 thagentleman

thagentleman

  • Members
  • 6 posts
  • OFFLINE
  •  
  • Local time:09:07 AM

Posted 16 February 2006 - 10:37 AM

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);
}
}

BC AdBot (Login to Remove)

 


m

#2 Craigory

Craigory

  • Members
  • 4 posts
  • OFFLINE
  •  
  • Local time:09:07 AM

Posted 18 February 2006 - 02:17 PM

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, '>'.

#3 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:08:07 AM

Posted 22 February 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.

#4 Craigory

Craigory

  • Members
  • 4 posts
  • OFFLINE
  •  
  • Local time:09:07 AM

Posted 11 March 2006 - 05:47 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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users