Results 1 to 10 of 10
  1. #1
    exeye0h's Avatar
    exeye0h is offline Member
    Join Date
    Jan 2012
    Location
    Chicago, IL, USA
    Posts
    40
    Rep Power
    0

    Question My for-loop is supposedly not a "statement".

    This is my code:

    import java.util.*;

    public class Tax{

    static Scanner sc = new Scanner(System.in);

    public static void main(String [] args) {

    int type; //type == 0
    double tax;
    double income;


    double [] rates = {0, 0.10, 0.15, 0.25, 0.28, 0.33, 0.35};

    double [][] bounds = { {0, 8500, 34500, 83600, 174400, 379150},
    {0, 17000, 69000, 139350, 212300, 379150},
    {0, 8500, 34500, 69675, 106150, 189575},
    {0, 12150, 46250, 119400, 193350, 379,150} };

    double [][] base = { {0, 850, 4750, 17025, 42449, 110016.5},
    {0, 1700, 9500, 27087.5, 47513.5, 102574},
    {0, 850, 4750, 13543.75, 23756.75, 51287},
    {0, 1215, 6330, 24615.5, 45323.5, 106637.5} };

    String [] type = {"Single", "Married Filing Jointly", "Married Filing Separately", "Head of Household"};

    System.out.printf("\n\n\tWelcome to 2011 Federal Income Tax Calculator", new Object[0]);

    String s;


    do {
    System.out.printf("\n\n\tOptions:");

    System.out.printf("\n\t1 for Single, 2 for Married Filing Jointly");

    System.out.printf("\n\t3 for Married Filing Separately 4 for Head of household");

    System.out.printf("\n\t0 to quit.");

    System.out.printf("\n\n\tPlease enter your choice:");

    int idx = scanner.nextInt(); // this is for the type, once the user puts in 0, the program will opt out.

    if(idx < 1 || idx > 4)
    break;

    System.out.printf("\n\n\tPlease enter your taxable income:");

    double income = sc.nextDouble();


    for (idx = 5, idx >= 0, idx--){

    if (income > bounds[type][idx])
    tax = base[type][idx] + (income - bounds[type][idx])*rates[idx];
    break;
    } while(true);
    System.out.printf("\n\n\n\tYour filing status is ", ' " ' + type[idx-1] + ' " ');

    System.out.printf("\n\n\tYour taxable income amount is $%-15.2f\n", Double.value0f(income));

    System.out.printf("\n\tYour tax due is $%-15.2f\n", Double.value0f(tax));

    double txrt;
    if(income > 0.0)
    txrt = tax / income;
    else
    txrt = 0.0;
    System.out.printf("\n\tYour effective tax rate is %4.2f%%", Double.valueOf(txrt * 100));

    System.out.printf("\n\n\n\tDo you want to continue for another computation? (Y/N) ");
    s = scanner.next();

    } while(s.equalsIgnoreCase("Y"));

    System.out.printf("\n\n\n\tThanks for using CSC211 Tax Calculator\n\n");

    }

    When I tried compiling the program, this is what my Terminal spat at me:


    ap-234-209:csc211 Xio$ javac TaxAns.java
    TaxAns.java:54: not a statement
    for (idx = 5, idx >= 0, idx--){
    ^
    TaxAns.java:54: ';' expected
    for (idx = 5, idx >= 0, idx--){
    ^
    TaxAns.java:60: unclosed character literal
    System.out.printf("\n\n\n\tYour filing status is " + ' " ' + type[idx-1] + ' " ');
    ^
    TaxAns.java:60: unclosed character literal
    System.out.printf("\n\n\n\tYour filing status is " + ' " ' + type[idx-1] + ' " ');
    ^
    TaxAns.java:60: ')' expected
    System.out.printf("\n\n\n\tYour filing status is " + ' " ' + type[idx-1] + ' " ');
    ^
    TaxAns.java:62: ')' expected
    System.out.printf("\n\n\tYour taxable income amount is $%-15.2f\n" + Double.value0f(income));
    ^
    TaxAns.java:81: '}' expected
    ^
    7 errors
    nap-234-209:csc211 Xio$ javac TaxAns.java
    TaxAns.java:54: not a statement
    for (idx = 5, idx >= 0, idx--){
    ^
    TaxAns.java:54: ';' expected
    for (idx = 5, idx >= 0, idx--){
    ^
    TaxAns.java:60: unclosed character literal
    System.out.printf("\n\n\n\tYour filing status is ", ' " ' + type[idx-1] + ' " ');
    ^
    TaxAns.java:60: unclosed character literal
    System.out.printf("\n\n\n\tYour filing status is ", ' " ' + type[idx-1] + ' " ');
    ^
    TaxAns.java:60: ')' expected
    System.out.printf("\n\n\n\tYour filing status is ", ' " ' + type[idx-1] + ' " ');
    ^
    TaxAns.java:62: ')' expected
    System.out.printf("\n\n\tYour taxable income amount is $%-15.2f\n", Double.value0f(income));
    ^
    TaxAns.java:81: '}' expected
    ^
    7 errors


    ):

    My assignment is to use two dimensional array to store those tax brackets and 1-dimensional array for tax rates. Your application will prompt the user for filing status and taxable income amount. Then it will display user's filing status and taxable income with tax due amount and the effective tax rate (where effective tax rate = ( tax due) / (taxable income). )

    My output is supposed to look something like this:
    Welcome to 2011 Federal Income Tax Calculator

    Options:
    1 for Single, 2 for Married Filing Jointly
    3 for mMarried Filing Separately 4 for Head of household
    0 to quit.

    Please enter your choice:1

    Please enter your taxable income:5000


    Your filing status is "Single",

    Your taxable income amount is $50000.00

    Your tax due is $8625.00

    Your effective tax rate is 17.25%

    Do you want to continue for another computation? (Y/N) y

    Options:
    1 for Single, 2 for Married Filing Jointly
    3 for mMarried Filing Separately 4 for Head of household
    0 to quit.

    Please enter your choice:4

    Please enter your taxable income:50000


    Your filing status is "Head of Household",

    Your taxable income amount is $50000.00

    Your tax due is $7267.50

    Your effective tax rate is 14.54%


    Do you want to continue for another computation? (Y/N) n


    Thanks for using CSC211 Tax Calculator

    (Just posting this additional information to put my program into perspective.)

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: My for-loop is supposedly not a "statement".

    Java Code:
    for(int i=4; <condition>; <step>)
    Can you see what is different between mine and yours?

  3. #3
    exeye0h's Avatar
    exeye0h is offline Member
    Join Date
    Jan 2012
    Location
    Chicago, IL, USA
    Posts
    40
    Rep Power
    0

    Default Re: My for-loop is supposedly not a "statement".

    I believe I do; you assigned "i" to be read as an integer.

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: My for-loop is supposedly not a "statement".

    There is something else you have confused, Hint: You used one in your response to me.

  5. #5
    exeye0h's Avatar
    exeye0h is offline Member
    Join Date
    Jan 2012
    Location
    Chicago, IL, USA
    Posts
    40
    Rep Power
    0

    Default Re: My for-loop is supposedly not a "statement".

    I just figured that out literally a minute ago haha. Thank you!
    I tried compiling it again and I still have errors (three less this time around).
    TaxAns.java:60: unclosed character literal
    System.out.printf("\n\n\n\tYour filing status is ", ' " ' + type[idx-1] + ' " ');
    ^
    TaxAns.java:60: unclosed character literal
    System.out.printf("\n\n\n\tYour filing status is ", ' " ' + type[idx-1] + ' " ');
    ^
    TaxAns.java:60: ')' expected
    System.out.printf("\n\n\n\tYour filing status is ", ' " ' + type[idx-1] + ' " ');
    ^
    TaxAns.java:81: '}' expected
    ^
    4 errors


    I JUST got rid of the "+" so I suppose my question is how do I get a particular String [] type array back in System.out.print?
    My assumption was type[idx-1] because the user will enter "1" for "Single" yet "Single" in the array type is actually type[0] hence the idx-1 but obviously Java is not agreeing with me.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: My for-loop is supposedly not a "statement".

    Show your latest code and the actual error message. Also please use [code] [/code] tags when posting code so it is readable.

    Also, you'll want to change your coding style so as to not run into this situation again: many errors on top of many errors. What you want to do is compile early and often when adding code to a program. Then if a compilation error crops up, fix it before adding any more code. Either that or use an IDE which compiles immediately as you add code.

  7. #7
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: My for-loop is supposedly not a "statement".

    Why do you have ' " ' ? You may want to check out where your strings end and begin.

    Java Code:
    "\n\n\n\tYour filing status is ", ' " ' + type[idx-1] + ' " '
    Your error is here, try figuring out what is wrong, you editors highlighting may help you here.

  8. #8
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: My for-loop is supposedly not a "statement".

    With a little bit of white space added...

    Java Code:
    for (idx = 5,    idx >= 0,  idx--) // <-- yours
    for (int i=4; <condition>; <step>) // <-- sunde's

  9. #9
    Bestsanchez is offline Member
    Join Date
    Jan 2012
    Location
    The Coffee Pot
    Posts
    36
    Rep Power
    0

    Default Re: My for-loop is supposedly not a "statement".

    Java Code:
    for (idx = 5, idx >= 0, idx--){
    
        if (income > bounds[type][idx])
            tax = base[type][idx] + (income - bounds[type][idx])*rates[idx];
        break;
    } while(true); // <-- Why is this here?
    
    System.out.printf("\n\n\n\tYour filing status is ", ' " ' + type[idx-1] + ' " ');

  10. #10
    exeye0h's Avatar
    exeye0h is offline Member
    Join Date
    Jan 2012
    Location
    Chicago, IL, USA
    Posts
    40
    Rep Power
    0

    Default Re: My for-loop is supposedly not a "statement".

    I have resorted to consulting with my professor so thank you all for helping me out in the best ways you could.
    Bestsanchez, my professor had just pointed that out to me today so yes! That while should not be there.

Similar Threads

  1. Replies: 1
    Last Post: 02-01-2012, 09:37 PM
  2. An "if" statement inside a "for" loop?
    By soccermiles in forum New To Java
    Replies: 18
    Last Post: 04-20-2010, 04:44 AM
  3. Replies: 3
    Last Post: 05-25-2009, 09:50 PM
  4. Replies: 0
    Last Post: 03-16-2009, 12:53 AM
  5. Replies: 1
    Last Post: 10-20-2008, 08:35 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
  •