473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

if-else statement

I have looked over this program numerous of times and cant seem to get it running, can some one please guide me in the right direction.
My error information is AnnualSalary.java:33: ' ) ' expected if (AnnualSalary <= 15,000) {


Expand|Select|Wrap|Line Numbers
  1.  /*
  2.  * AnnualSalary.java
  3.  *
  4.  * Created on September 18, 2007, 9:56 AM
  5.  *
  6.  * To change this template, choose Tools | Template Manager
  7.  * and open the template in the editor.
  8.  */
  9.  
  10. package AnnualSalary;
  11.  
  12. /**
  13.  *
  14.  * @author felde301
  15.  */
  16. import javax.swing.JOptionPane;
  17.  
  18. public class AnnualSalary {
  19.  
  20.     /** Creates a new instance of AnnualSalary */
  21.     public AnnualSalary() {
  22.     }
  23.  
  24.     /**
  25.      * @param args the command line arguments
  26.      */
  27.     public static void main(String[] args) {
  28.        JOption.showInputDialog (null,"Enter an annual salary:",
  29.                JOptionPane.QUESTION_MESSAGE);
  30.  
  31.  
  32.  
  33.        if (AnnualSalary <= 15,000){
  34.  
  35.            taxratecategory = '1';
  36.  
  37.        }else if (AnnualSalary <= 15,000 - 25,000)
  38.  
  39.            {
  40.  
  41.                taxratecategory = '2';
  42.  
  43.     }else  if (AnnualSalary => 25,001 - 40,000)
  44.         {
  45.  
  46.             taxratecategory = '3';
  47.  
  48.     }else if (AnnualSalary => 40,0001 - 65,000)
  49.         {
  50.  
  51.             taxratecategory = '4';
  52.         }else if (AnnualSalary => 65,001 - 80,000)
  53.             {
  54.  
  55.            taxratecategory = '5';
  56.  
  57.     }else if (AnnualSalary => 80,000)
  58.  
  59.     taxratecategory = '6';
  60.  
  61.             //end if
  62.  
  63.        //display the result
  64.  
  65.        JOptionPane.showMessageDialog(null, "The tax rate category for an annual salary");
  66.  
  67.  
  68.     }
  69.  
  70. }
Sep 20 '07 #1
6 2081
r035198x
13,262 8TB
I have looked over this program numerous of times and cant seem to get it running, can some one please guide me in the right direction.
My error information is AnnualSalary.java:33: ' ) ' expected if (AnnualSalary <= 15,000) {


/*
* AnnualSalary.java
*
* Created on September 18, 2007, 9:56 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package AnnualSalary;

/**
*
* @author felde301
*/
import javax.swing.JOptionPane;

public class AnnualSalary {

/** Creates a new instance of AnnualSalary */
public AnnualSalary() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
JOption.showInputDialog (null,"Enter an annual salary:",
JOptionPane.QUESTION_MESSAGE);



if (AnnualSalary <= 15,000){

taxratecategory = '1';

}else if (AnnualSalary <= 15,000 - 25,000)

{

taxratecategory = '2';

}else if (AnnualSalary => 25,001 - 40,000)
{

taxratecategory = '3';

}else if (AnnualSalary => 40,0001 - 65,000)
{

taxratecategory = '4';
}else if (AnnualSalary => 65,001 - 80,000)
{

taxratecategory = '5';

}else if (AnnualSalary => 80,000)

taxratecategory = '6';

//end if

//display the result

JOptionPane.showMessageDialog(null, "The tax rate category for an annual salary");


}

}
1.) Use code tags
2.) Remove all those commas from the amounts.

Edit: And now that I can see the code better under code tags, => is not a valid operator. Use >= instead.
You have to declare variables before you can use them and each variable should have a type.
Sep 20 '07 #2
Thanks for you help I was able to get it running but am not getting the correct output. I should be able to enter a salary and it should tell me waht tax catergory am in.

Output should look like this

Enter an annual salary (ex...40350) => 34400

The tax rate category for an annual salary of $34400 is 3

Expand|Select|Wrap|Line Numbers
  1.  /*
  2.  * AnnualSalary.java
  3.  *
  4.  * Created on September 18, 2007, 9:56 AM
  5.  *
  6.  * To change this template, choose Tools | Template Manager
  7.  * and open the template in the editor.
  8.  */
  9.  
  10. package annualsalary;
  11.  
  12. /**
  13.  *
  14.  * @author felde301
  15.  */
  16. import javax.swing.JOptionPane;
  17.  
  18. public class AnnualSalary {
  19.  
  20.     /** Creates a new instance of AnnualSalary */
  21.     public AnnualSalary() {
  22.     }
  23.  
  24.     /**
  25.      * @param args the command line arguments
  26.      */
  27.     public static void main(String[] args) {
  28.  
  29.     float annualsalary = 0;
  30.      float taxratecategory = 0;
  31.  
  32.        JOptionPane.showInputDialog (null,"Enter an annual salary:",
  33.                JOptionPane.QUESTION_MESSAGE);
  34.  
  35.  
  36.  
  37.        if (annualsalary <= 15000){
  38.  
  39.            taxratecategory = '1';
  40.  
  41.        }else if (annualsalary <= 15000 - 25000)
  42.  
  43.            {
  44.  
  45.                taxratecategory = '2';
  46.  
  47.     }else  if (annualsalary <= 25001 - 40000)
  48.         {
  49.  
  50.             taxratecategory = '3';
  51.  
  52.     }else if (annualsalary <= 400001 - 65000)
  53.         {
  54.  
  55.             taxratecategory = '4';
  56.         }else if (annualsalary <= 65001 - 80000)
  57.             {
  58.  
  59.            taxratecategory = '5';
  60.  
  61.     }else if (annualsalary >= 80000)
  62.  
  63.     taxratecategory = '6';
  64.  
  65.             //end if
  66.  
  67.        //display the result
  68.  
  69.        JOptionPane.showMessageDialog(null, "The tax rate category for an annual salary");
  70.  
  71.  
  72.     }
  73.  
  74. }
Sep 20 '07 #3
r035198x
13,262 8TB
You forgot the code tags again. You have to read what's being replied to you to be able to get the most out of these forums.
Sep 20 '07 #4
JosAH
11,448 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1.  
  2. float annualsalary = 0;
  3. JOptionPane.showInputDialog (null,"Enter an annual salary:",
  4.                JOptionPane.QUESTION_MESSAGE);
  5. if (annualsalary <= 15000){
  6. ...
  7. }
How is the JOptionPane to know that what you enter there has to be automagically
stuffed into your 'annualsalary' variable? Computers aren't psychic you know.

kind regards,

Jos
Sep 20 '07 #5
r035198x
13,262 8TB
.. Computers aren't psychic you know.

kind regards,

Jos
Turing would be disappointed by that statement of course.
Quite an exotic bit of code that by the OP.
Sep 20 '07 #6
JosAH
11,448 Expert 8TB
Turing would be disappointed by that statement of course.
Nope, Alan Turing already knew that computers are soooo stupid. Even more:
there were no computers in those days; Alan was a clever dicky.

kind regards,

Jos ;-)
Sep 20 '07 #7

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

Similar topics

1
by: John Ryan | last post by:
What PHP code would I use to check if submitted sites to my directory actually exist?? I want to use something that can return the server code to me, ie HTTP 300 OK, or whatever. Can I do this with...
2
by: Sugapablo | last post by:
My brain is frozen on a convenient way to figure out if today is the 1st, 2nd, 3rd, 4th, or last Thursday of the month. Basically I need something that will figure this out for any given day for...
6
by: GazK | last post by:
I have an image viewing page which resizes an image to a sensible sizebefore displaying. The user should then be able to choose "25% larger" or smaller and the resized image display. The problem I...
5
by: george | last post by:
Guys and girls, I'll be quite honest. I don't have the faintest idea how to do this, while I can do other php without a problem. Once I know how to go about it I'll be okay. It's two things I...
0
by: Phil Powell | last post by:
....is it not true that mysql_error() will persist? I have a case on a site where the admin enters a new user and, for some reason, does it wrong, producing a mysql_error() instance. If they try...
1
by: krystoffff | last post by:
Hi all ! I've got a very weird problem ! I was trying to make my PHP script to send emails to every subscribed member to go faster (each email takes 1 or 2 seconds to be sent !) so I tried to...
2
by: Leif Wessman | last post by:
I need help creating a regular expression to find the subdomain in the $HTTP_HOST variable. The domain is always in this form: www.domain.com or uk.domain.com or domain.com
0
by: Sébastien | last post by:
Hi there, If I call mergeProfiles() only one time, it is fine. However, if I call it more than one time (say twice), then it will returns a segmentation fault... any ideas? $res is a result...
1
by: Ron Hiler | last post by:
Hi guys, I'm a C++ programmer, and I have created a game which has a client/server architecture. What I would like to do is have my web page show if the server is up and how many people are...
1
by: sam | last post by:
Is there a simple way to test if a mysql table exists? JUST One line !
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.