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);
}
If Statement problem.
Page 1 of 19 Replies - 836 Views - Last Post: 24 October 2010 - 09:26 AM
#1
If Statement problem.
Posted 23 October 2010 - 11:56 AM
Hi I want to make an IF statement in java for this situation:
Replies To: If Statement problem.
#2
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){}
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*/}
#3
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
The operator && is undefined for the argument type(s) boolean, int
#4
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?
#5
Re: If Statement problem.
Posted 23 October 2010 - 09:49 PM
if (annualIncome >=0 && annualIncome <= 2100 && maritalStatus.equals("single"))
#6
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);
}
}
}
#7
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.
#8
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
#9
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,
#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) ) ){
if ( (pictureupdate.equals("true") ) && ( ReplaceImage = (true) ) ){
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote







|