By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,361 Members | 1,700 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,361 IT Pros & Developers. It's quick & easy.

Issues with Illegal characters =/

P: 8
I wrote this program to calculate the income tax of a user depending on whether or not they were married:

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.JOptionPane;
  2.  
  3. public class Income_Tax
  4. {
  5.     public static void main (String [] args)
  6.     {
  7.  
  8.     String married = "yes";
  9.     String single = "no";
  10.     String status;
  11.     String inputIncome;
  12.     int income;
  13.     double tax;
  14.  
  15.  
  16.     status = JOptionPane.showInputDialog("Are you Married? /n(yes or no) /n");
  17.  
  18.     inputIncome = JOptionPane.showInputDialog("Enter your Income : ");
  19.  
  20.     income = Integer.parseInt(inputIncome);
  21.  
  22.     if (status.equals(married))
  23.         {
  24.             if (income >200300)
  25.                 {
  26.                     tax = ((65100–0)*(0.15))+((131450–65100)*(0.25))+((200300–131450)*(0.28))+((income–200300)*(0.33));                }
  27.  
  28.             else if (income >131450 && income <=200300)
  29.                 {
  30.                     tax = ((65100–0)*(0.15))+((131450–65100)*(0.25))+((income–131450)*(0.28));
  31.                 }
  32.  
  33.             else if (income >65100 && income <=131450)
  34.  
  35.                 {
  36.                     tax = ((65100–0)*(0.15))+((income–65100)*(0.25));
  37.                 }
  38.  
  39.             else if (income >0 && income <= 65100)
  40.  
  41.                 {
  42.                     tax = ((income–0)*(0.15));
  43.                 }
  44.  
  45.             else
  46.  
  47.                 {
  48.                      JOptionPane.showMessageDialog(null, "\nError: Income cannot be 0 or less ");
  49.                 } 
  50.  
  51.         }
  52.  
  53.     else if (status.equals(single));
  54.         {
  55.             if (income >164550)
  56.                 {
  57.                     tax = ((32550–0)*(0.15))+((78850–32550)*(0.25))+((164550–32550)*(0.28))+((income–164550)*(0.33));
  58.                 }
  59.  
  60.             else if (income >78850 && income <=164550)
  61.                 {
  62.                     tax = ((32550–0)*(0.15))+((78850–32550)*(0.25))+((income–32550)*(0.28));
  63.                 }
  64.  
  65.             else if (income >32550 && income <=78850)
  66.  
  67.                 {
  68.                     tax = ((32550–0)*(0.15))+((income–32550)*(0.25));
  69.                 }
  70.  
  71.             else if (income >0 && income <= 32550)
  72.  
  73.                 {
  74.                     tax = ((income–0)*(0.15));
  75.                 }
  76.  
  77.             else
  78.  
  79.                 {
  80.                      JOptionPane.showMessageDialog(null, "\nError: Income cannot be 0 or less ");
  81.                 } 
  82.         }
  83.     else
  84.         {
  85.             JOptionPane.showMessageDialog(null, "\nError: Not a valid answer ");
  86.         }
  87.  
  88.     JOptionPane.showMessageDialog(null, "Your income tax is " + tax + " . " );
  89.  
  90.     System.exit(0); 
  91.  
  92.     }
  93.  
  94. }
  95.  
  96.  
But, I keep receiving these errors. And I don't know how to fix it ><;
So if I could get some help I'd greatly appreciate it!

Errors::
Expand|Select|Wrap|Line Numbers
  1. Income_Tax.java:30: illegal character: \8211
  2.                     tax = ((65100–0)*(0.15))+((131450–65100)*(0.25))+((200300–131450)*(0.28))+((income–200300)*(0.33));                }
  3.                                                      ^
  4. Income_Tax.java:30: illegal character: \8211
  5.                     tax = ((65100–0)*(0.15))+((131450–65100)*(0.25))+((200300–131450)*(0.28))+((income–200300)*(0.33));                }
  6.                                                                          ^
  7. Income_Tax.java:30: illegal character: \8211
  8.                     tax = ((65100–0)*(0.15))+((131450–65100)*(0.25))+((200300–131450)*(0.28))+((income–200300)*(0.33));                }
  9.                                                                                                  ^
  10. Income_Tax.java:30: illegal character: \8211
  11.                     tax = ((65100–0)*(0.15))+((131450–65100)*(0.25))+((200300–131450)*(0.28))+((income–200300)*(0.33));                }
  12.                                                                                                                           ^
  13. Income_Tax.java:30: ')' expected
  14.                     tax = ((65100–0)*(0.15))+((131450–65100)*(0.25))+((200300–131450)*(0.28))+((income–200300)*(0.33));                }
  15.                                                                                                                                           ^
  16. Income_Tax.java:34: illegal character: \8211
  17.                     tax = ((65100–0)*(0.15))+((131450–65100)*(0.25))+((income–131450)*(0.28));
  18.                                                      ^
  19. Income_Tax.java:34: illegal character: \8211
  20.                     tax = ((65100–0)*(0.15))+((131450–65100)*(0.25))+((income–131450)*(0.28));
  21.                                                                          ^
  22. Income_Tax.java:34: illegal character: \8211
  23.                     tax = ((65100–0)*(0.15))+((131450–65100)*(0.25))+((income–131450)*(0.28));
  24.                                                                                                  ^
  25. Income_Tax.java:34: ')' expected
  26.                     tax = ((65100–0)*(0.15))+((131450–65100)*(0.25))+((income–131450)*(0.28));
  27.                                                                                                                  ^
  28. Income_Tax.java:40: illegal character: \8211
  29.                     tax = ((65100–0)*(0.15))+((income–65100)*(0.25));
  30.                                                      ^
  31. Income_Tax.java:40: illegal character: \8211
  32.                     tax = ((65100–0)*(0.15))+((income–65100)*(0.25));
  33.                                                                          ^
  34. Income_Tax.java:40: ')' expected
  35.                     tax = ((65100–0)*(0.15))+((income–65100)*(0.25));
  36.                                                                                         ^
  37. Income_Tax.java:46: illegal character: \8211
  38.                     tax = ((income–0)*(0.15));
  39.                                                       ^
  40. Income_Tax.java:46: ')' expected
  41.                     tax = ((income–0)*(0.15));
  42.                                                                  ^
  43. Income_Tax.java:61: illegal character: \8211
  44.                     tax = ((32550–0)*(0.15))+((78850–32550)*(0.25))+((164550–32550)*(0.28))+((income–164550)*(0.33));
  45.                                                      ^
  46. Income_Tax.java:61: illegal character: \8211
  47.                     tax = ((32550–0)*(0.15))+((78850–32550)*(0.25))+((164550–32550)*(0.28))+((income–164550)*(0.33));
  48.                                                                         ^
  49. Income_Tax.java:61: illegal character: \8211
  50.                     tax = ((32550–0)*(0.15))+((78850–32550)*(0.25))+((164550–32550)*(0.28))+((income–164550)*(0.33));
  51.                                                                                                 ^
  52. Income_Tax.java:61: illegal character: \8211
  53.                     tax = ((32550–0)*(0.15))+((78850–32550)*(0.25))+((164550–32550)*(0.28))+((income–164550)*(0.33));
  54.                                                                                                                         ^
  55. Income_Tax.java:61: ')' expected
  56.                     tax = ((32550–0)*(0.15))+((78850–32550)*(0.25))+((164550–32550)*(0.28))+((income–164550)*(0.33));
  57.                                                                                                                                         ^
  58. Income_Tax.java:66: illegal character: \8211
  59.                     tax = ((32550–0)*(0.15))+((78850–32550)*(0.25))+((income–32550)*(0.28));
  60.                                                      ^
  61. Income_Tax.java:66: illegal character: \8211
  62.                     tax = ((32550–0)*(0.15))+((78850–32550)*(0.25))+((income–32550)*(0.28));
  63.                                                                         ^
  64. Income_Tax.java:66: illegal character: \8211
  65.                     tax = ((32550–0)*(0.15))+((78850–32550)*(0.25))+((income–32550)*(0.28));
  66.                                                                                                 ^
  67. Income_Tax.java:66: ')' expected
  68.                     tax = ((32550–0)*(0.15))+((78850–32550)*(0.25))+((income–32550)*(0.28));
  69.                                                                                                                ^
  70. Income_Tax.java:72: illegal character: \8211
  71.                     tax = ((32550–0)*(0.15))+((income–32550)*(0.25));
  72.                                                      ^
  73. Income_Tax.java:72: illegal character: \8211
  74.                     tax = ((32550–0)*(0.15))+((income–32550)*(0.25));
  75.                                                                          ^
  76. Income_Tax.java:72: ')' expected
  77.                     tax = ((32550–0)*(0.15))+((income–32550)*(0.25));
  78.                                                                                         ^
  79. Income_Tax.java:78: illegal character: \8211
  80.                     tax = ((income–0)*(0.15));
  81.                                                       ^
  82. Income_Tax.java:78: ')' expected
  83.                     tax = ((income–0)*(0.15));
  84.                                                                  ^
  85. Income_Tax.java:87: 'else' without 'if'
  86.     else
  87.         ^
  88. 29 errors
  89.  

Thank you so much in advance!!
Feb 27 '09 #1
Share this Question
Share on Google+
2 Replies


sharat87
P: 6
I was able to spot four problems in your code dear..
1. its not the generally used subtraction operator you are using. It is something else.. I have no idea what the character is.
2. the semicolon on line 53... that is what is causing the error 'else withou an if', remove that semicolon and you are good
3. variable tax has not been initialised.. give it some initial value like -1
4. convert tax to string before you add it to another string on line 88

I dont have X display do I could only compile it.. i could not run it.. I give you the fixed code.. 'cause I dont know if you will be able to get the correct character for the subtraction operator.. i am attaching it because it may be the display on the browser that's distorting the characters :)

and... please honor the java coding standards... do not use 'underscores' in class names (and method names too for that matter).

regards,
sharat87
Attached Files
File Type: zip IncomeTax.zip (762 Bytes, 101 views)
Feb 28 '09 #2

Expert 10K+
P: 11,448
Check your keyboard: character 8211 (see the error messages) is unicode characer \2013 which is a dash somewhere in the Chinese character set. It may look like an ordinary minus sign but it is a totally different character.

kind regards,

Jos

ps. the other errors are simple unbalanced parentheses errors.
Feb 28 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.