Greetings all. I am having a problem with getting java program to produce the correct output. I am being asked to use conditional logic to determine a tax rate category. I am not getting any syntax errors at all but I am not getting the correct code after putting in the annual salary as directed.
Here is my code. Any help in pointing me in the right direction will be greatly appreciated.
import javax.swing.JOptionPane;
public class TaxCodeTest1 {
public static void main(String[] args) {
float salary = 0;
float code = 0;
JOptionPane.showInputDialog(null,
"Enter annual salary, example 10000",
"Input",
JOptionPane.QUESTION_MESSAGE);
if (salary < 15000) { //Salary less than 15000 code 1
code = '1';
JOptionPane.showMessageDialog(null, " Tax Code =" + 1);
}
else if (salary >= 15001 - 25000) { //salary between 15001 - 25000 code 2
code = '2';
JOptionPane.showMessageDialog(null, " Tax Code =" + 2);
}
else if (salary >= 25001 - 40000) { //salary between 25001 - 40000 code 3
code = '3';
}
else if (salary >= 40001 - 65000) { //salary between 40001 - 65000
code = '4';
}
else if (salary >= 65001 - 80000) { //salary between 65001 - 80000
code = '5';
}
else if (salary > 80000) { //salary greater than 80000
code = '6';
JOptionPane.showMessageDialog(null, "The code based on annual salary") ;
}
}
}
6 1794
You can't test whether or not a value lies in an interval that way: the '-' symbol
actually means subtraction so the compiler (that doesn't know what you want to
do) compiles your code but your compiled code does quite something different
from what you want to accomplish.
If you want to check whether or not a value 'v' lies in an interval 'lo' ... 'hi' do this: -
if (lo <= v && v < hi) ...
-
The interval is 'half open' i.e. the interval is [lo, hi)
kind regards,
Jos
Greetings all. I am having a problem with getting java program to produce the correct output. I am being asked to use conditional logic to determine a tax rate category. I am not getting any syntax errors at all but I am not getting the correct code after putting in the annual salary as directed.
Here is my code. Any help in pointing me in the right direction will be greatly appreciated.
import javax.swing.JOptionPane;
public class TaxCodeTest1 {
public static void main(String[] args) {
float salary = 0;
float code = 0;
JOptionPane.showInputDialog(null,
"Enter annual salary, example 10000",
"Input",
JOptionPane.QUESTION_MESSAGE);
if (salary < 15000) { //Salary less than 15000 code 1
code = '1';
JOptionPane.showMessageDialog(null, " Tax Code =" + 1);
}
else if (salary >= 15001 - 25000) { //salary between 15001 - 25000 code 2
code = '2';
JOptionPane.showMessageDialog(null, " Tax Code =" + 2);
}
else if (salary >= 25001 - 40000) { //salary between 25001 - 40000 code 3
code = '3';
}
else if (salary >= 40001 - 65000) { //salary between 40001 - 65000
code = '4';
}
else if (salary >= 65001 - 80000) { //salary between 65001 - 80000
code = '5';
}
else if (salary > 80000) { //salary greater than 80000
code = '6';
JOptionPane.showMessageDialog(null, "The code based on annual salary") ;
}
}
}
1) Use code tags when posting code.
2.) Your salary is always 0. You did not assign the value entered to the salary variable.
You can't test whether or not a value lies in an interval that way: the '-' symbol
actually means subtraction so the compiler (that doesn't know what you want to
do) compiles your code but your compiled code does quite something different
from what you want to accomplish.
If you want to check whether or not a value 'v' lies in an interval 'lo' ... 'hi' do this: -
if (lo <= v && v < hi) ...
-
The interval is 'half open' i.e. the interval is [lo, hi)
kind regards,
Jos
Hey, haven't we seen this code before?
Hey, haven't we seen this code before?
Yup, l'histoire se repete as the Germans say ;-)
kind regards,
Jos
Yup, l'histoire se repete as the Germans say ;-)
kind regards,
Jos
I prefer king Solomon's "There is nothing new under the sun".
I prefer king Solomon's "There is nothing new under the sun".
As in "been there; done that"? ;-)
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bruce |
last post by:
Which of the popular templating systems (e.g. PHLib, FastTemplate,
Smarty) allow you to setup conditions in your templates, for example:
<-- IF Variable=value -->
this HTML
<-- ELSEIF...
|
by: Reinhold Birkenfeld |
last post by:
Hi,
after Guido's pronouncement yesterday, in one of the next versions of Python
there will be a conditional expression with the following syntax:
X if C else Y
which is the same as today's...
|
by: Chuck Reed |
last post by:
I am working on a sales report where I show weekly sales by category
for each of the 52 weeks in the year. Each record in my table/report
has the 52 weeks of sales in it. I want to highlight to top...
|
by: Raghavendra R A V, CSS India |
last post by:
hie..
Do any one knows how to write a C program without using the
conditional statements if, for, while, do, switch, goto and even
condotional statements ? It would be a great help for me if...
|
by: Robert Zurer |
last post by:
In his paper on Coding Standard found on
http://www.idesign.net/idesign/DesktopDefault.aspx
Juval Lowy discourages the use of the ternary conditional operator with no
specific reason given.
...
|
by: John |
last post by:
Hi
I have an app to deal with two companies A & B within a group of companies
depending on which database is selected. Is it possible for setup to ask the
user at install time which company they...
|
by: booksnore |
last post by:
..eh I was stuck thinking up a subject title for this post for a while..
So I am processing a really big file (scary big). Each record is fixed
length, I need to test conditions on certain fields...
|
by: Basilisk96 |
last post by:
This topic is difficult to describe in one subject sentence...
Has anyone come across the application of the simple statement "if
(object1's attributes meet some conditions) then (set object2's...
|
by: mikebrengartner |
last post by:
Hi all,
I've got a data bound list view that I'm trying to work with. I'm
trying to fill out the item template with a table row that displays a
link to a file if the job status is complete. I've...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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...
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |