It won't compile

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • paradox6996
    New Member
    • Jul 2007
    • 21

    #1

    It won't compile

    Here is the error:

    01C.java
    Program01C.java :9: <identifier> expected
    import static java.lang.Math. *;
    ^
    Program01C.java :9: '.' expected
    import static java.lang.Math. *;
    ^
    2 errors

    Here is the code:

    Code:
    //Robert Burns
    //Feb. 5, 2009
    //paradox6996@gmail.com
    //Program01B-Calculates total average of test scores
    
    import java.util.Scanner;
    
    //Math class so I can truncate doubles to get nice looking decimals
    import static java.lang.Math.*;
    
    public class Program01C {
      
       public static void main(String[] args) {
    
        double purchase, totalTax, salesTax, countyTax, total, totalSalestax, totalCountytax;
        
        salesTax = 0.04;
        countyTax = 0.02;
      
      
       Scanner keyboard = new Scanner(System.in);
       System.out.print("Enter the Amount of Purchase:");
       purchase = keyboard.nextDouble();
      
       totalSalestax = (purchase * salesTax);
       totalCountytax = (purchase * countyTax);
       totalTax = (salesTax + countyTax);
       total = (((totalTax) * purchase) + purchase);
       
       System.out.printf("Sales Tax: " + totalSalestax + "\nCounty Tax: " + totalCountytax + "\nTotal Sales Tax: " + totalTax + "\nPurchase Amount: " + purchase + "\nTotal Amount: %.2f", total, Math.ceil(total));
    I've gotten it to compile before so idk why it isn't working now. Any ideas?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    You don't have to explicitly import anything from the java.lang package; it has been done implicitly for you.

    kind regards,

    Jos

    ps. what is your compiler version? btw, the forum software swallows leading spaces so the caret in the error message doesn't show up at the correct location. Better make the error messages a code block.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Yep, the version must be the problem here. Static imports are only here with us after version 1.5.
      P.S If you do a static import of
      Code:
       import static java.lang.Math.*;
      , then you don't need to say Math.ceil in the code. Just say ceil. Otherwise there is no point in having that static import in there at all.

      Comment

      • paradox6996
        New Member
        • Jul 2007
        • 21

        #4
        I figured it out last night I have Gentoo linux and somehow blackdown JDK was selected as the compiler and it doesn't support static imports. I selected JDK 1.6 and all worked fine. Thanx for the replies though.

        Paradox(>")>

        Comment

        Working...