" '.class' expected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pantherxin
    New Member
    • Apr 2010
    • 12

    " '.class' expected

    I am getting .class expected at debugging for line 16 "sale = input.nextDoubl e[ ]

    Code:
    import java.util.Scanner; // program uses class Scanner
    
    public class SalesCommission
    {
    	public static void main( String args[] )
    	{
            // create Scanner for input from command window
    	    Scanner input = new Scanner( System.in );
    
    		double sale[] = { 200-299,300-399, 400-499, 500-599, 600-699, 700-799, 800-899, 900-999, 1000-9999 };
    				
    		System.out.println( "Enter gross sales amount: " ); //prompt  user for input
    		sale = input.nextDouble[];
    		 
    		// find commission for individual salary range
    		for ( int counter = 0; counter < sale.length; counter++ );
    		{
    			// output salary range
    			if ( sale == 1000 )
                    System.out.print( "%3f-%3f: ",
    				sale[8] = sale[8] * .09 + 200 );
    			else
    				System.out.print( "%3f-%3f: ",
    				sale[8] = sale[8] + 1 );
    	
    			System.out.printf( "%s%8s\n", "Sales", "Salary" );
    		} // end for
       } // end main
    } // end class SalesCommission
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Use () instead of []

    Comment

    • pantherxin
      New Member
      • Apr 2010
      • 12

      #3
      Tried ( ) originally and again; got error for that line and additional errors.

      c:\Jassign>java c SalesCommission .java
      SalesCommission .java:16: incompatible types
      found : double
      required: double[]
      sale = input.nextDoubl e();
      ^
      SalesCommission .java:22: incomparable types: double[] and int
      if ( sale == 1000 )
      ^
      SalesCommission .java:23: cannot find symbol
      symbol : method print(java.lang .String,double)
      location: class java.io.PrintSt ream
      System.out.prin t( "%3f-%3f: ",
      ^
      SalesCommission .java:26: cannot find symbol
      symbol : method print(java.lang .String,double)
      location: class java.io.PrintSt ream
      System.out.prin t( "%3f-%3f: ",
      ^

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        oh wait. You're misunderstandin g the array
        { 200-299,300-399, 400-499, 500-599, 600-699, 700-799, 800-899, 900-999, 1000-9999 };
        gives you an array
        { -99, -99, -99, -99, -99, -99, -99, -99, -8999}
        as it treats - as minus or subtract.


        You need a secondary double variable to set the output to.
        I would set your array to be the lower limits, eg
        { 200,300, 400, 500, 600, 700, 800, 900, 1000};

        Your comparison method will have to change as well.

        Comment

        • pantherxin
          New Member
          • Apr 2010
          • 12

          #5
          Unfortunately, our assignment calls for 200-299, 300-399, etc. I have since tried something that will list the salaries, if I remove " sale = input.nextInt ". However, I cannot enter salaries and complete the other requirements of calculating bonuses. Thanks anyway!

          Comment

          • jkmyoung
            Recognized Expert Top Contributor
            • Mar 2006
            • 2057

            #6
            You can't store ranges in a double array. Either find a class that stores ranges and lets you compare them easily, or use a different loop to find where within the range it fits.

            eg:
            if sale >= 1000
            On second thought, make it an int array:
            int[] saleRange = { 200,300, 400, 500, 600, 700, 800, 900, 1000, 10000};
            The range of the i'th element is
            saleRange[i-1] to (saleRange[i]-1)

            Comment

            Working...