Need Help W/ Writing a Program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Levar
    New Member
    • Oct 2007
    • 6

    Need Help W/ Writing a Program

    I have tried all I know and still continue to get errors in my program can any one give me some guidance? I would be grateful. What I wrote is:

    import java.text.*;// For using DecimalFormat class for 2 decimal places
    import java.util.*;// For using Scanner class for input

    public class Tax
    {
    public static void main(String [] args)
    {
    Scanner key = new Scanner(System. in);
    DecimalFormat twoDec = new DecimalFormat(" $0.00");
    Taxable income = 0.0, Tax payable = 0.0;
    System.out.prin t("Enter Taxable income ($): \t");
    Taxable income = Key.nextDouble( );
    if (Taxable income < 1.00)
    {
    System.out.prin t("Error: Taxable income cannot be less than 1.00");
    }
    else
    {
    if (Taxable income <= 4461.99)
    {
    Tax payable = 0.00 * 4461.99;
    }
    else if (Taxable income <= 17893.99)
    {
    Tax payable = 0.30 * 17894.00;
    }
    else if (Taxable income <= 29499.99)
    {
    Tax payable = 4119.00 && 0.35 * 17894.00;
    }
    else if (Taxable income <= 45787.99)
    {
    Tax payable = 8656.00 && 0.46 * 29500.00;
    }
    else
    {
    Tax payable = 11179.00 && 0.60 * 45788.00
    }
    System.out.prin tln("Enter Taxable income:");
    System.out.prin tln("0.99");
    System.out.prin tln("Taxable income:0.99");
    System.out.prin tln("Error: Taxable income cannot be less than 1.00");
    }
    }



    The errors I get is:

    ';' expected
    not a statement
    'else' without 'if'
    illegal start of type
    <identifier> expected
    class, interface, or enum expected
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Most probably...

    1.
    [code=java]
    //Taxable income = 0.0, Tax payable = 0.0;......wrong
    Taxable income = 0.0;
    Tax payable = 0.0;
    [/code]

    2.
    [code=java]
    //if(Taxable income < 1.00) ........... this type of expression will be
    if(income < 1.00)
    [/code]

    3.
    One "}" is missing.
    Most probably it will be just after the last "else block" finishes.

    Debasis Jana

    Comment

    • madhoriya22
      Contributor
      • Jul 2007
      • 251

      #3
      Originally posted by Levar
      I have tried all I know and still continue to get errors in my program can any one give me some guidance? I would be grateful. What I wrote is:

      import java.text.*;// For using DecimalFormat class for 2 decimal places
      import java.util.*;// For using Scanner class for input

      public class Tax
      {
      public static void main(String [] args)
      {
      Scanner key = new Scanner(System. in);
      DecimalFormat twoDec = new DecimalFormat(" $0.00");
      Taxable income = 0.0, Tax payable = 0.0;
      System.out.prin t("Enter Taxable income ($): \t");
      Taxable income = Key.nextDouble( );
      if (Taxable income < 1.00)
      {
      System.out.prin t("Error: Taxable income cannot be less than 1.00");
      }
      else
      {
      if (Taxable income <= 4461.99)
      {
      Tax payable = 0.00 * 4461.99;
      }
      else if (Taxable income <= 17893.99)
      {
      Tax payable = 0.30 * 17894.00;
      }
      else if (Taxable income <= 29499.99)
      {
      Tax payable = 4119.00 && 0.35 * 17894.00;
      }
      else if (Taxable income <= 45787.99)
      {
      Tax payable = 8656.00 && 0.46 * 29500.00;
      }
      else
      {
      Tax payable = 11179.00 && 0.60 * 45788.00
      }
      System.out.prin tln("Enter Taxable income:");
      System.out.prin tln("0.99");
      System.out.prin tln("Taxable income:0.99");
      System.out.prin tln("Error: Taxable income cannot be less than 1.00");
      }
      }



      The errors I get is:

      ';' expected
      not a statement
      'else' without 'if'
      illegal start of type
      <identifier> expected
      class, interface, or enum expected
      Hi,
      Can u explain me what is this ..
      Code:
      Taxable income = 0.0, Tax payable = 0.0;
      If these are variables u r declaring .. then this way of declaring variables is completely wrong. You can't provide spaces while declaring variables. Even you hav not provided the type of variables.

      Comment

      • Levar
        New Member
        • Oct 2007
        • 6

        #4
        Debasis Jana,

        Thank you so very much for the guidance it helped greatly. Could you give me another tip please? I have two errors now after following what you mention. One is this line:

        Tax payable = 11179.00 && 0.60 * 45788.00

        and the error is:

        ';' expected


        the other is this line:

        }

        and the error is:

        reached end of file while parsing

        if you can help Thank you if not still Thank you!






        Originally posted by dmjpro
        Most probably...

        1.
        [code=java]
        //Taxable income = 0.0, Tax payable = 0.0;......wrong
        Taxable income = 0.0;
        Tax payable = 0.0;
        [/code]

        2.
        [code=java]
        //if(Taxable income < 1.00) ........... this type of expression will be
        if(income < 1.00)
        [/code]

        3.
        One "}" is missing.
        Most probably it will be just after the last "else block" finishes.

        Debasis Jana

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          What does it mean ...

          "Tax payable = 11179.00 && 0.60 * 45788.00"
          What do you want to do here?

          And post me d full code with code tags what you changed.

          Debasis Jana

          Comment

          • Levar
            New Member
            • Oct 2007
            • 6

            #6
            This is what I have now:



            import java.text.*;// For using DecimalFormat class for 2 decimal places
            import java.util.*;// For using Scanner class for input

            public class Tax
            {
            public static void main(String [] args)
            {
            Scanner key = new Scanner(System. in);
            DecimalFormat twoDec = new DecimalFormat(" $0.00");
            Taxable income = 0.0;
            Tax payable = 0.0;
            System.out.prin t("Enter Taxable income ($): \t");
            Taxable income = Key.nextDouble( );
            if (income < 1.00)
            {
            System.out.prin t("Error: Taxable income cannot be less than 1.00");
            }
            else
            {
            if (income <= 4461.99)
            {
            Tax payable = 0.00 * 4461.99;
            }
            else if (income <= 17893.99)
            {
            Tax payable = 0.30 * 17894.00;
            }
            else if (income <= 29499.99)
            {
            Tax payable = 4119.00 && 0.35 * 17894.00;
            }
            else if (income <= 45787.99)
            {
            Tax payable = 8656.00 && 0.46 * 29500.00;
            }
            else
            {
            Tax payable = 11179.00 && 0.60 * 45788.00;
            }
            System.out.prin tln("Enter Taxable income:");
            System.out.prin tln("0.99");
            System.out.prin tln("Taxable income:0.99");
            System.out.prin tln("Error: Taxable income cannot be less than 1.00");
            }
            }




            And I would the only problem now is the last line it is giving me the error:

            reached end of file while parsing

            and I don't know why

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by Levar
              The errors I get is:

              ';' expected
              not a statement
              'else' without 'if'
              illegal start of type
              <identifier> expected
              class, interface, or enum expected
              That was not what you saw after compilation. The compiler showed you line numbers
              and the exact position on the line where it found the mistake. You don't want us
              to start guessing do you? You should show us what you saw verbatim. Computer
              programming languages are not about vague guesses or whatever; programming
              is about as much information you can supply, either the computer itself (it did
              supply as much information), or you, when you pass those error diagnostics to us.

              kind regards,

              Jos

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Please do not post the same code over and over again.
                And if you really have to post code, post only the relevant parts and use code tags.
                You have some illegal statements in your code. Refer to your textbook on operators and how to use them legally in Java.

                Comment

                Working...