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 3 of 3

Thread: tax return program..help finish please!!

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default tax return program..help finish please!!

    i am supposed to write a program using nested if/else statements and print the federal tax based on whether the user enter, single or married and how much their income is.

    the user should be able to run the program over and over until he/she types 'done'

    this is the tax table i have to follow...

    single married (percentage stays the same)
    tax bracket percentage tax bracket
    $0....$8,050 10% $0....$16,050

    Amount over $8,050, Amount over $16,050,
    up to $78,850 25% up to $131,450

    Amount over $78,850, Amount over $131,450,
    up to $187,550 30% up to $250,000

    Amount over $187,550 35% Amount over $250,050



    //Algorithm
    //1.Enter whether you are single or married.
    //2.Enter your income as a whole number.
    //3.

    import java.util.Scanner; //so I can use a scanner
    public class computeTax
     {
        public static void main (String[] args)
       {
               Scanner in = new Scanner(System.in);
               System.out.print("Enter whether you are single or married.");
              String line = in.next();
    i am unsure how to declare single or married somewhere once the user enters it and im unsure how to make it work for the user to type done..

    please help!!
    Last edited by helloworld922; November 3rd, 2009 at 09:53 PM.


  2. #2
    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: tax return program..help finish please!!

    I'm assuming the user is going to be typing in either "married" or "single" (exactly in that format, without the quotes):

    This is easy to solve by using a boolean flag to denote if the person is married.
    boolean isMarried = false;
    if ("married".equals(line))
    {
         isMarried = true;
    }

    Then, when you need to do different stuff depending on if they're married or not, use an if/else statement:
    if (isMarried)
    {
         // stuff to do if they're married
    }
    else
    {
         // stuff to do if they're not married (single)
    }

  3. #3
    Junior Member
    Join Date
    Oct 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: tax return program..help finish please!!

    yes but i need to have tax included....


    java.import.util.*;

    public class computeTax
    {
    public static void main(String[] args)
    {
    Scanner in = new Scanner(system.in);

    System.out.print("Please type single, if you are single, or married, if you are married.");
    String s = in.next();
    String m = in.next();

    System.out.print("Please enter your income as a whole number.");
    int income = in.nextInt();

    }

    }

Similar Threads

  1. Missing Return Statement in If-elseIf-else
    By chronoz13 in forum Loops & Control Statements
    Replies: 2
    Last Post: October 12th, 2009, 07:01 AM
  2. Prime number generator program missing return statement
    By 03EVOAWD in forum What's Wrong With My Code?
    Replies: 13
    Last Post: September 10th, 2009, 09:17 AM
  3. Error of "Class has no return statement"
    By mdstrauss in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 2nd, 2009, 12:00 PM
  4. Error of missing return statement while implementing Array
    By MS_Dark in forum Collections and Generics
    Replies: 1
    Last Post: December 10th, 2008, 03:18 PM