Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Help I'm stuck on code.

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking Help I'm stuck on code.

    I'm trying to get the following assignment completed but I seem to be stuck.. If I can get help I would appreciate it. This is whats required of the of the program.

    I am to write a program that will calculate a person's income tax based upon the following table.
    Income -------------------------- Percent Withheld
    0 - $10,000 ------------------- 0%
    $10,000.01 - $25,000 --------------------- 10%
    $25,000.01 - $50,000 -------------------- 20%
    > $50,000.01 -------------------- 35%

    Than my program should read in the annual salary, calculate the monthly pay, and then remove the income tax. After that print out the yearly salary, gross monthly pay, net monthly pay, and the amount of the monthly withholding.

    I have done the input prompts for the annual salary and monthly pay. I seem to be stuck on removing the income tax and how I would go about the printout output for the net pay and monthly withholding.
    Here is what I have so far.. I presume I will need to use an if else statement but not sure how to set it up.. any help I'll be sure to return it?
    import java.text.DecimalFormat;
    public class IncomeTaxCalc {
    	public static void main(String[] args) {
    	    double salary;
    	    double pay;
    	    double netPay;
    	    salary = GetData.getDouble("Enter yearly salary");
    	    pay = salary / 12.0; 
    	    netPay = 
    	    DecimalFormat myNumber = new DecimalFormat("$#,##0.00");
    	    System.out.println("Yearly salary: " + salary + "\n"+"Gross Monthly Pay:" 
    	    		+ pay + "\n"+"New Monthly Pay:" + "\n"+"Witholding:" + );
    }//end main
    }//end class
    Last edited by helloworld922; January 27th, 2010 at 10:58 PM.


  2. #2
    Junior Member
    Join Date
    Jan 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help I'm stuck on code.

    14 views not 1 reply?

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Help I'm stuck on code.

    Patience

    Those who can answer your question are not on 24/7

    A simple way to implement this logically is by comparing the income with the maximum values of each range using if-else statements (can you see why?)

    Also, it's important to figure out if $10000 belongs to the lower bracket or the higher bracket (also with the other brackets). This will determine if you need a < or a <= operator.

    double taxRate = 0;
    if (pay< 10000)
    {
         taxRate = 0;
    }
    else if (pay < 25000)
    {
         taxRate = 0.1;
    }
    else if (pay < 50000)
    {
         taxRate = .2;
    }
    else
    {
         // pay > 50000
         taxRate = .3;
    }

  4. #4
    Junior Member
    Join Date
    Jan 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help I'm stuck on code.

    Quote Originally Posted by helloworld922 View Post
    Patience

    Those who can answer your question are not on 24/7

    A simple way to implement this logically is by comparing the income with the maximum values of each range using if-else statements (can you see why?)

    Also, it's important to figure out if $10000 belongs to the lower bracket or the higher bracket (also with the other brackets). This will determine if you need a < or a <= operator.

    double taxRate = 0;
    if (pay< 10000)
    {
         taxRate = 0;
    }
    else if (pay < 25000)
    {
         taxRate = 0.1;
    }
    else if (pay < 50000)
    {
         taxRate = .2;
    }
    else
    {
         // pay > 50000
         taxRate = .3;
    }
    thanks for your help

Similar Threads

  1. I'm stuck
    By iank in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 5th, 2009, 10:21 AM
  2. Replies: 24
    Last Post: April 14th, 2009, 03:43 PM
  3. Problem while programming a simple game of Car moving on a road
    By rojroj in forum Java Theory & Questions
    Replies: 3
    Last Post: April 2nd, 2009, 10:24 AM
  4. stuck on this program can any one help me
    By clive in forum AWT / Java Swing
    Replies: 2
    Last Post: March 10th, 2009, 05:54 PM