0

What I am trying to do is test the values of two variables, and if one is lower than the other then it will display an error message. When the user clicks okay it should return from the error pop-up back to the previous form... When I enter System.exit(0); or break;. it will terminate the program, is there a better syntax ?

My code:

//Declare and initialize variables
        int income = 0;
	int houseCost = 0;

	//Assigns data from text field to variables
	Income = Integer.parseInt(txtIncome.getText());
	houseCost = Integer.parseInt(txtHouseCost.getText());
		
	//Is income less than house cost ?
	if (income < houseCost)
	{
	      JOptionPane.showMessageDialog(null, "Your income is less than your housing cost.", "Error", JOptionPane.ERROR_MESSAGE);
	}
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by matt4682
1

If you're in a method, which you have to be, you could say "return;". I wouldn't worry about it too much if you have a working method though.

0

If you're in a method, which you have to be, you could say "return;". I wouldn't worry about it too much if you have a working method though.

Ah, thank you ! The only reason I was wondering is because when in this case, income is less than houseCost, it would produce a logic error from insufficient funds to pay for your house and the label in which the answer is output to would be a false answer.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.