Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-17-2007, 06:00 PM
Member
 
Join Date: Jul 2007
Posts: 26
romina is on a distinguished road
Problem with equation in my algorithm
Here is the entire code everything compiles ok, but when I run the application, the total I'm looking for comes out as a negative, I need it to come out as a positive. The equation given to compute the state tax is 0.03 x (Income - (600 x # of dependents).

Code:
import java.io.*; public class StateTax { public static void main(String[] args) throws IOException { //declares and constructs variables String income, dependents; int amt, amt2; double stateTax; BufferedReader dataIn= new BufferedReader(new InputStreamReader(System.in)); //print prompts and get input System.out.println("\tSTATE TAX COMPUTATION"); System.out.println(); System.out.print("\t\tEnter Taxpayer's Income: "); income = dataIn.readLine(); amt = Integer.parseInt(income); System.out.println(); System.out.print("\t\tEnter Number of Dependents: "); dependents = dataIn.readLine(); amt2 = Integer.parseInt(dependents); System.out.println(); //calculations stateTax = .03 * ((double)amt - (600 * amt2)); //output System.out.println(); System.out.println("\tSTATE TAX DUE IS " + stateTax + "."); System.out.println(); } }
Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-20-2007, 08:34 AM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
I don't see anything wrong in the code, maybe it's the input ur entering for this calculation that's too small
Code:
//calculations stateTax = .03 * ((double)amt - (600 * amt2));
The equation will surely give a negative value if the income are too small right
I tried putting the minimum value of 600 for a dependant of 1,and it runs just ok
If u don't want it to go negative, just put an if clause to prevent it
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-20-2007, 08:53 AM
Member
 
Join Date: Jul 2007
Posts: 9
shameel is on a distinguished road
what cruxblack said is write, nothing wrong with ur code.based on ur formula,
if u give the value of amt greater than 600 and give the value of amt2 1 then only u will get positive value[amt=601,amt2=1 will be small positive value in this formula].according to this way u have to give values, otherwise give some restrictions in the time of values input, like amt would be > 600, like something.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with an equation in java coco New To Java 1 07-31-2007 08:47 AM
Help with quadratic equation in java paul New To Java 1 07-25-2007 09:23 PM
Problem with algorithm Albert AWT / Swing 1 07-13-2007 04:31 PM
Help with Algorithm Daniel Advanced Java 2 07-02-2007 06:51 AM
Algorithm problem Marcus Advanced Java 2 07-01-2007 02:37 AM


All times are GMT +3. The time now is 05:14 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org