Results 1 to 9 of 9
  1. #1
    fstarter1 is offline Member
    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Unhappy Please assist with illegal start of expression

    I get error message illegal start of expression, please assist.

    Here is the code

    Java Code:
    import java.util.Scanner;
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    
    /**
     *
     * @author SLD
     */
    public class AnnualCompensation{ 
    
    static Scanner userInput = new Scanner(System.in);
        
    public static void main(String[] args)
    {
        
    private double yearlySalary;  THIS LINE IS WHERE I GET " illegal start of expression "
    private double monthlySalary;
    private double annualSales;
    private double commission;
    private double salesTarget;
    private double incentiveRate;
    
        /**
         * @param args the command line arguments
         */
        public AnnualCompensation(){
            // salesperson will earn a fixed monthly salary of $4,166
            double setYearlySalary = 500000.00;
        // The current sales target for every salesperson is $120,000.00
        setSalesTarget(120000.00);
        //The acceleration factor is 1.25
        setIncentiveRate(1.5);  
        }
        
        // function get annual sales
        public double getaAnnualSales(){
            return annualSales;
        }
        
       public void readData(){
            Scanner in = new Scanner(System.in);
            System.out.print("Please enter annual sales: ");
            // get annual sales
            annualSales = in.nextInt();
       } 
        
       public void calculateCommission(){
            // The current commission is 0.5% of total sales
            if (annualSales < 80.0*salesTarget/100.0)
                commission = 0;
            else
                if (annualSales <= salesTarget)
                    //The current commission is 5% of total sales
                    commission = 0.5 * annualSales / 100.0;
                else
                    commission = 0.5 * annualSales / 100.0 + incentiveRate * annualSales;
        }
           
           
       public double getCommission(){
            return commission;
       } 
    
        // function get total annual compensation
        public double getTotalAnnualCompensation (){
            return yearlySalary + getCommission();
       }
      
        // funtion set value for monthlySalary
        public void setMonthlySalary(double monthlySalary){
            this.monthlySalary = monthlySalary;
       } 
        
        
         // funtion set value for salesTarget
        public static void setSalesTarget(double salesTarget){
            this.salesTarget = salesTarget;
        }
    
        public static void setIncentiveRate(double incentiveRate ){
            this.incentiveRate = incentiveRate;
        } 
        
        public void displayResult(){
        double maxValue;
            maxValue = 1.5 * annualSales;
            System.out.println("Total Sales	    Total Compensation");
            // until it reaches 50% above the salespersons annual sales. 
            while (annualSales <= maxValue) {
                calculateCommission();
                System.out.println("$ " + annualSales + "             " + (monthlySalary + commission) + " $");
                // in $5000 increments above the salespersons annual sales
                annualSales += 5000;
                }
         }
    }
    Last edited by pbrockway2; 12-25-2012 at 01:16 AM. Reason: code tags added

  2. #2
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: Please assist with illegal start of expression

    Why do you declare a scope when you are inside your main() method??? ;)
    How about removing the "private"?
    I like likes!

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

    Default Re: Please assist with illegal start of expression

    Hi fstarter1, welcome to the forums!

    When you post code, use the "code" tags. Put [code] at the start of the code and [/code] at the end: that way the code will be formatted by the forum software and readable.

  4. #4
    fstarter1 is offline Member
    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Default Re: Please assist with illegal start of expression

    Quote Originally Posted by Sierra View Post
    Why do you declare a scope when you are inside your main() method??? ;)
    How about removing the "private"?


    Many thanks, ok so I removed the private it worked. But now I have Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - missing method body, or declare abstract at AnnualCompensation.main(AnnualCompensation.java:16 )

    I though I declared my main method...please know I'm so new to this...and basically so confused by my own code. Your help is appreciated.

  5. #5
    fstarter1 is offline Member
    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Default Re: Please assist with illegal start of expression

    Thanks, I will use the tags moving forward.

  6. #6
    ieee488 is offline Member
    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0

    Default Re: Please assist with illegal start of expression

    What is double setYearlySalary = 500000.00;?
    Is that suppose to be a method? If so, there isn't one in the rest of your code and that is not how you use a method to set a private variable.
    Is it suppose to be a variable? Declared this way, it can't be used anywhere else in your code.

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

    Default Re: Please assist with illegal start of expression

    The best way to avoid being confused by ones own code is to work one step one (small) step at a time. And have a clear idea what you intend at each step. At each step compile and deal with any messages that arise.

    I have a suspicion that those "private" modifiers were meant to be there. That is, you intended them to be instance variables of the class. In that case they should not have been inside the main() method. Likewise you have all sorts of other stuff that appear to be constructors and methods wrongly placed inside the main() method.

    But to go back to the problem of "private", try the following:

    Java Code:
    public class AnnualCompensation{
     
        static Scanner userInput = new Scanner(System.in);
    
        private double yearlySalary;
        private double monthlySalary;
        private double annualSales;
        // etc
    
        public AnnualCompensation() {
            // etc
        }
    
        public double getaAnnualSales(){
            // etc
        }
    
        // etc - other methods go here
    
        public static void main(String[] args) {
            // etc
        }
    }
    The ordering - variables, constructors, methods, main() method - is traditional.

    That "template" might useful but, if it is, use it as a guide to where you are heading. Start again with your own code checking with the compiler as you add things and resolving problems as they arise.

  8. #8
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: Please assist with illegal start of expression

    To be honest, looking at your new code I think you have no clue what you are doing. I suggest you start a tutorial for learning the basics of Java.
    What you did was to remove the complete start of the main() method and all variables that will probably be important later.
    The code snippet pbrockway2 gave is helpful, but I think you will get nowhere on yourself, if you do not know what you are doing.
    Who gave the template to you and what were you supposed to do with it?
    I like likes!

  9. #9
    fstarter1 is offline Member
    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Default Re: Please assist with illegal start of expression

    Thanks for your help, I will start over and use snippet from pbrockway2. Here I go.

Similar Threads

  1. Illegal start of expression
    By Robster in forum New To Java
    Replies: 3
    Last Post: 11-26-2011, 08:43 AM
  2. Illegal Start of Expression
    By Tyre in forum New To Java
    Replies: 20
    Last Post: 04-15-2011, 03:50 PM
  3. illegal start of expression
    By rajivjoshi in forum New To Java
    Replies: 3
    Last Post: 05-31-2010, 10:12 AM
  4. Illegal start of expression
    By Basit56 in forum New To Java
    Replies: 2
    Last Post: 08-18-2009, 10:12 AM
  5. Illegal Start of Expression
    By vince425 in forum New To Java
    Replies: 3
    Last Post: 10-18-2008, 08:41 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
  •