9 Replies - 836 Views - Last Post: 24 October 2010 - 09:26 AM Rate Topic: -----

#1 jay134  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 29
  • Joined: 17-October 10

If Statement problem.

Posted 23 October 2010 - 11:56 AM

Hi I want to make an IF statement in java for this situation:


import javax.swing.JOptionPane;

public class TaxReturn {


	public static void main(String[] args) {

		// Declaring Variables 

		int sinNumber;
		String lastName, firstName, streetAddress, city, maritalStatus, annualIncomeString, sinString;
		double annualIncome, taxLiability; 

		//Welcome message  and instructions

		JOptionPane.showMessageDialog(null,"Hi, Welcome to Perera Tax calculator." + 
				" \n Please have the following information to complete the process." + 
				"\n Your: \n Sin Number, Address, Marital Status, Annual Income" +
				"\n Thank you.");
		JOptionPane.showMessageDialog(null, "Please complete the following questionnaire.");

		//Collecting data

		firstName = JOptionPane.showInputDialog("What is your First name? ");
		lastName = JOptionPane.showInputDialog("What is your Last name? ");
		streetAddress = JOptionPane.showInputDialog("What is your street address? (excluding postal code, province/state, country) ");
		city = JOptionPane.showInputDialog("Which city are you located in? ");
		maritalStatus = JOptionPane.showInputDialog("Are you single or married?");
		annualIncomeString = JOptionPane.showInputDialog("What is your Annual Income?");
		annualIncome = Double.parseDouble(annualIncomeString);
		sinString = JOptionPane.showInputDialog("What is your Sin Number? (No Spaces)");
		sinNumber = Integer.parseInt(sinString);

If (annualIncome is 0 -21000 && maritalStatus = "single") //I need help with this part
{
annualIncome = annualIncome *1.15;
System.out.println("your income is: " + annualIncome); 
}
else
{
annualIncome = annualIncome *1.15;
System.out.println("your income is: " + annualIncome);
}
		




Is This A Good Question/Topic? 0
  • +

Replies To: If Statement problem.

#2 fallenreaper  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 240
  • Joined: 19-June 10

Re: If Statement problem.

Posted 23 October 2010 - 12:12 PM

you know, you pretty much solved it yourself. You used pseudocode, just need to translate it into java syntax.

Set up of the IF statement

if(item1 [compare operator such as <, > , =] item2 [&&/|| more items){}

if (annualIncome >=0 && annualIncome <= 21000 && maritalStatus.compareTo("single")){/*insert stuff*/}else{/*insert stuff*/}

Was This Post Helpful? 0
  • +
  • -

#3 jay134  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 29
  • Joined: 17-October 10

Re: If Statement problem.

Posted 23 October 2010 - 12:20 PM

it is giving me this error


The operator && is undefined for the argument type(s) boolean, int
Was This Post Helpful? 0
  • +
  • -

#4 jay134  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 29
  • Joined: 17-October 10

Re: If Statement problem.

Posted 23 October 2010 - 12:46 PM

if (annualIncome >=0 && annualIncome <= 2100){ //&& maritalStatus.compareTo("single")
			
			taxLiability = annualIncome *1.15;
			System.out.println("your tax liability is: " + taxLiability); 
			
			}
		else
			{
			
			taxLiability = annualIncome *1.15;
			System.out.println("your tax liability is: " + taxLiability); 
			
			}


We can only compare two boolean expressions
The problem is maritalStatus is not a boolean...

any ideas on how to fix this?
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8019
  • View blog
  • Posts: 31,126
  • Joined: 06-March 08

Re: If Statement problem.

Posted 23 October 2010 - 09:49 PM

if (annualIncome >=0 && annualIncome <= 2100 && maritalStatus.equals("single"))
Was This Post Helpful? 0
  • +
  • -

#6 jay134  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 29
  • Joined: 17-October 10

Re: If Statement problem.

Posted 23 October 2010 - 10:59 PM

Still getting errors... please advise.


import javax.swing.JOptionPane;

public class TaxReturn {


	public static void main(String[] args) {
		
		// Declaring Variables 
		
		int sinNumber;
		String lastName, firstName, streetAddress, city, maritalStatus, annualIncomeString, sinString;
		double annualIncome, taxLiability; 
		
		//Welcome message  and instructions
		
		JOptionPane.showMessageDialog(null,"Hi, Welcome to Perera Tax calculator." + 
				" \n Please have the following information to complete the process." + 
				"\n Your: \n Sin Number, Address, Marital Status, Annual Income" +
				"\n Thank you.");
		JOptionPane.showMessageDialog(null, "Please complete the following questionnaire.");
		
		//Collecting data
		
		firstName = JOptionPane.showInputDialog("What is your First name? ");
		lastName = JOptionPane.showInputDialog("What is your Last name? ");
		streetAddress = JOptionPane.showInputDialog("What is your street address? (excluding postal code, province/state, country) ");
		city = JOptionPane.showInputDialog("Which city are you located in? ");
		maritalStatus = JOptionPane.showInputDialog("Are you single or married?");
		annualIncomeString = JOptionPane.showInputDialog("What is your Annual Income?");
		annualIncome = Double.parseDouble(annualIncomeString);
		sinString = JOptionPane.showInputDialog("What is your Sin Number? (No Spaces)");
		sinNumber = Integer.parseInt(sinString);
		
	
		
		if (annualIncome >=0 && annualIncome <= 2100)&& maritalStatus.compareTo("single"){
			
			taxLiability = annualIncome *1.15;
			System.out.println("your tax liability is: " + taxLiability); 
			
			}
		else
			{
			
			taxLiability = annualIncome *1.15;
			System.out.println("your tax liability is: " + taxLiability); 
			
			}
		if (annualIncome >=21001 && annualIncome <= 50000)&& maritalStatus.compareTo("single"){
			
			taxLiability = annualIncome *1.22;
			System.out.println("your tax liability is: " + taxLiability); 
			
			}
		else
			{
			
			taxLiability = annualIncome *1.20;
			System.out.println("your tax liability is: " + taxLiability); 
			
			}
		if (annualIncome >=0 && annualIncome <= 2100) && maritalStatus.compareTo("single"){
			
			taxLiability = annualIncome *1.30;
			System.out.println("your tax liability is: " + taxLiability); 
			
			}
		else
			{
			
			taxLiability = annualIncome *1.28;
			System.out.println("your tax liability is: " + taxLiability); 
			
			}
	}

}




Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 9029
  • View blog
  • Posts: 33,490
  • Joined: 27-December 08

Re: If Statement problem.

Posted 23 October 2010 - 11:59 PM

What specific errors are you encountering? Post the error messages and line numbers in question.
Was This Post Helpful? 0
  • +
  • -

#8 Handler  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 199
  • Joined: 01-April 10

Re: If Statement problem.

Posted 24 October 2010 - 12:16 AM

if (annualIncome >=0 && annualIncome <= 2100) && maritalStatus.compareTo("single")


should not have the ) behind 2100 remove it out all the ifs.
Then put a ) behind single

if (annualIncome >=0 && annualIncome <= 2100 && maritalStatus.compareTo("single"))


must look like that
Was This Post Helpful? 0
  • +
  • -

#9 jay134  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 29
  • Joined: 17-October 10

Re: If Statement problem.

Posted 24 October 2010 - 08:04 AM

when i do that its giving me this error: The operator && is undefined for the argument type(s) boolean,
Was This Post Helpful? 0
  • +
  • -

#10 Your Restrain  Icon User is offline

  • New D.I.C Head

Reputation: -9
  • View blog
  • Posts: 19
  • Joined: 23-October 10

Re: If Statement problem.

Posted 24 October 2010 - 09:26 AM

Here is an example of a correct if statement with AND:

if ( (pictureupdate.equals("true") ) && ( ReplaceImage = (true) ) ){
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1