Results 1 to 3 of 3
 07172007, 05:00 PM #1Member
 Join Date
 Jul 2007
 Posts
 26
 Rep Power
 0
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).
Java 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(); } }
 07202007, 07:34 AM #2Senior Member
 Join Date
 Jul 2007
 Posts
 130
 Rep Power
 0
I don't see anything wrong in the code, maybe it's the input ur entering for this calculation that's too small
Java Code://calculations stateTax = .03 * ((double)amt  (600 * amt2));
I tried putting the minimum value of 600 for a dependant of 1,and it runs just ok :D
If u don't want it to go negative, just put an if clause to prevent it :)
 07202007, 07:53 AM #3Member
 Join Date
 Jul 2007
 Posts
 9
 Rep Power
 0
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.
Similar Threads

Help with an equation in java
By coco in forum New To JavaReplies: 1Last Post: 07312007, 07:47 AM 
Help with quadratic equation in java
By paul in forum New To JavaReplies: 1Last Post: 07252007, 08:23 PM 
Problem with algorithm
By Albert in forum AWT / SwingReplies: 1Last Post: 07132007, 03:31 PM 
Help with Algorithm
By Daniel in forum Advanced JavaReplies: 2Last Post: 07022007, 05:51 AM 
Algorithm problem
By Marcus in forum Advanced JavaReplies: 2Last Post: 07012007, 01:37 AM
Bookmarks