The Artima Developer Community
Sponsored Link

Java Answers Forum
need help !

2 replies on 1 page. Most recent reply: Mar 29, 2004 1:39 AM by rod

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
rod

Posts: 2
Nickname: rexona
Registered: Mar, 2004

need help ! Posted: Mar 28, 2004 6:10 AM
Reply to this message Reply
Advertisement
I am very new to Java as you will no doubt quickly realise although I do believe everyone had to start somewhere!

Ok I am trying to achieve getting two inputs from user(age, income) and apply a tax rate to the income and if there over 50 apply a 10% discount in taxable income.

First part seems easy and works although I stumped on how to reduce the income figure given by the user before apply the tax.

What Ive got is this -

import java.io.*;

class TaxationCalculator

{
public static void main (String []args)
throws IOException
{
//create an input stream

BufferedReader stdin = new BufferedReader (new
InputStreamReader (System.in));

// declare variables

String income, age;

int ageNum, incomeNum, tax = 0;


// retrieve income and age from user

System.out.print(" Input your total income:");

income = stdin.readLine ();

incomeNum = Integer.parseInt(income);


System.out.print(" Input your age:");

age = stdin.readLine ();

ageNum = Integer.parseInt(age);


// print the result

System.out.println (" Their tax payable is:" + (double)tax);



// determine and calculate if tax reduction due to age





if ( ageNum > 50)
incomeNum=(incomeNum) * 10/100;





// calculate tax
if (incomeNum <= 6000)
tax = (0);

if (incomeNum > 6000 && incomeNum<= 21600)
tax = ((incomeNum - 6000) * 17/100);

if (incomeNum > 21600 && incomeNum<= 52000)
tax = ((incomeNum - 21600) * 30/100 + 2652);

if (incomeNum > 52000 && incomeNum<= 62500)
tax = ((incomeNum - 52000) * 42/100 + 11772);

if (incomeNum > 62501)
tax = ((incomeNum - 62500) * 30/100 + 16182);


}




}


twc

Posts: 129
Nickname: twc
Registered: Feb, 2004

Re: need help ! Posted: Mar 28, 2004 11:46 AM
Reply to this message Reply
a. I would think that income would be a double, not an int

b. If they get a 10% discount, then they pay taxes on 90% of their income. Multiply by .9. BTW, don't use 90/100 because 90/100 comes out to 0 due to integer division. If you must use a fraction, use 90.0/100.0 to force the quotient to be a double. You probably will experience similar problems with the other fractions that you have listed.

c. I might create another variable called taxableIncome which would equal incomeNum if they are under 50, but be 90% of incomeNum if they are 50 or over. That way you retain the original income value if you need it later. If you do this, don't forget to use taxableIncome in your calculations in the if statement.

I hope this helps.
twc

rod

Posts: 2
Nickname: rexona
Registered: Mar, 2004

Re: need help ! Posted: Mar 29, 2004 1:39 AM
Reply to this message Reply
thanks twc!

Followed your advice (a,b & c) now works perfectly!!

No doubt youll see me posting more requests here as I get more into java!

Thanks again

Flat View: This topic has 2 replies on 1 page
Topic: reference to non-static variable from a static context..problems! Previous Topic   Next Topic Topic: HELP! Runtime.getRuntime().exec(

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use