Results 1 to 3 of 3
  1. #1
    romina is offline Member
    Join Date
    Jul 2007
    Posts
    26
    Rep Power
    0

    Default 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();
    }
    }
    Thanks

  2. #2
    cruxblack is offline Senior Member
    Join Date
    Jul 2007
    Posts
    130
    Rep Power
    0

    Default

    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));
    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 :D
    If u don't want it to go negative, just put an if clause to prevent it :)

  3. #3
    shameel is offline Member
    Join Date
    Jul 2007
    Posts
    9
    Rep Power
    0

    Default

    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

  1. Help with an equation in java
    By coco in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 07:47 AM
  2. Help with quadratic equation in java
    By paul in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 08:23 PM
  3. Problem with algorithm
    By Albert in forum AWT / Swing
    Replies: 1
    Last Post: 07-13-2007, 03:31 PM
  4. Help with Algorithm
    By Daniel in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 05:51 AM
  5. Algorithm problem
    By Marcus in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 01:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •