Page 1 of 2 12 LastLast
Results 1 to 20 of 21
  1. #1
    Join Date
    Dec 2015
    Posts
    9
    Rep Power
    0

    Default I can't figure out what is wrong

    Hello everyone!

    I am putting together this program for my course and I don't know where I went wrong here. Here is my code:

    /*
    * To change this license header, choose License Headers in Project Properties.
    * To change this template file, choose Tools | Templates
    * and open the template in the editor.
    */
    package saleperson;

    /**
    *
    * @author James
    */
    public class SalePerson {
    double salary=60000;
    static double salesTarget=130000;
    double totalSales;
    double commisionRate=5;
    static double accelrationFactor=1.5;

    public SalePerson(double totalSales) {
    this.totalSales = totalSales;
    }
    public SalePerson() {
    }
    public static void main(String[] args) {
    public double totalCompensation(double totalSales)
    {
    if(totalSales<salesTarget)
    {
    if(totalSales>=(salesTarget*0.8))
    {
    return salary+totalSales*commisionRate/100;
    }
    else
    {
    return salary;
    }
    }
    else
    {
    return salary+(totalSales*commisionRate*accelrationFactor/100);
    }
    }
    }

    }

    }
    Last edited by jameswinfield3; 12-20-2015 at 10:50 PM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: I can't figure out what is wrong

    I don't know where I went wrong
    Please explain why you think there is something wrong.

    Please edit your post and wrap your code with code tags:
    [code]
    **YOUR CODE GOES HERE**
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    Dec 2015
    Posts
    9
    Rep Power
    0

    Default Re: I can't figure out what is wrong

    Hello everyone!

    I am putting together this program for my course and I don't know where I went wrong here. Here is my code:

    Java Code:
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package saleperson;
    
    /**
     *
     * @author James
     */
    public class SalePerson {
     double salary=60000;
        static double salesTarget=130000;
        double totalSales;
        double commisionRate=5;
        static double accelrationFactor=1.5;
        
        public SalePerson(double totalSales) {
            this.totalSales = totalSales;
        }
         public SalePerson() {
        }
        public static void main(String[] args) {
          [COLOR="#FF0000"]  public double totalCompensation(double totalSales[/COLOR]
        {
            if(totalSales<salesTarget)
            {
                if(totalSales>=(salesTarget*0.8))
                {
                    return salary+totalSales*commisionRate/100;
                }
                else
                {
                    return salary;
                }
            }
            else
            {
                return salary+(totalSales*commisionRate*accelrationFactor/100);
            }    
        }
    }
    
    [COLOR="#FF0000"] }[/COLOR]
        
    }

    I'm using Netbeans and on line 25 its saying that it is an illegal start of an expression. I can't find how this is possible. On line 46 it is saying class, interface or enum expected. These are the only issues that are coming up and hopefully I can get it to run.
    Last edited by jameswinfield3; 12-20-2015 at 11:15 PM.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: I can't figure out what is wrong

    line 25 its saying that it is an illegal start of an expression.
    You can not define a method inside of another method. The new method's definition must be after the } that ends the previous method's definition.

    On line 46 it is saying class, interface or enum expected.
    Check that the { and } are properly matched.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Join Date
    Dec 2015
    Posts
    9
    Rep Power
    0

    Default Re: I can't figure out what is wrong

    I had written the wrong code for the program that I am writing for my class and I have written another program that is required for the assignment. I have the main class that I need to have in the code to make it run. However, when I hit run it says build successful but I do not get any prompts to input any information at all.

    Java Code:
    package work;
    
    
        
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /**
     *
     * @author
     */
    public class Work {
        
        public static void main(String[] args) {
            
        }
        double salary=60000;
        static double salesTarget=130000;
        double totalSales;
        double commisionRate=5;
        static double accelrationFactor=1.5;
    
        public Work(double totalSales) {
            this.totalSales = totalSales;
        }
    
        public Work() {
        }
        
        public double totalCompensation(double totalSales)
        {
            if(totalSales<salesTarget)
            {
                if(totalSales>=(salesTarget*0.8))
                {
                    return salary+totalSales*commisionRate/100;
                }
                else
                {
                    return salary;
                }
            }
            else
            {
                return salary+(totalSales*commisionRate*accelrationFactor/100);
            }    
        }
    }

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: I can't figure out what is wrong

    do not get any prompts to input any information at all.
    Where did you write any code that would prompt for input? Can you post the line numbers where you think the program should prompt for input?
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: I can't figure out what is wrong

    Java Code:
    public static void main(String[] args) {         
    }
    Your main method does nothing.
    This is the first method that is called when you start your program, so in this case you have told Java to do nothing.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    Join Date
    Dec 2015
    Posts
    9
    Rep Power
    0

    Default Re: I can't figure out what is wrong

    I'm sorry for the late reply. I entered the prompts to enter data and now I'm having trouble finding the last error in this program.
    Java Code:
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /**
     *
     * @author James
     */
    public class NewMain {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
      public class SalesPerson {
     // create variable (fixedSalary)
     double fixedSalary;
     // variable of the value of sale person's annual sales
     double annualSales;
     //commission that is earned
     double commission;
     //The target for sales that must be reached by sales person
     double target;
     public SalesPerson(double annualSales) {
      this.annualSales = annualSales;
      target = 140000;
      commission = 0;
      if (annualSales > target * 0.8) {
       if (annualSales < target) commission = 0.25 * annualSales; //The current commission 25% of total sales.
       else commission = 0.25 * 1.25 * annualSales; //The current commission (0.25*1.25)% of total sales.
      }
      fixedSalary = 75000; // set fixed salary is 75000$
     }
     public double getTotalAnnualCompensation() { // calculate The total annual compensation is the fixed salary plus the commission earned
      return fixedSalary + commission;
     }
    }
        }
        
    }

  9. #9
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: I can't figure out what is wrong

    Why are you declaring a class inside of main (it isn't needed and you never instantiate it)? And please align your braces as your code is difficult to read.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  10. #10
    Join Date
    Dec 2015
    Posts
    9
    Rep Power
    0

    Default Re: I can't figure out what is wrong

    Quote Originally Posted by jim829 View Post
    Why are you declaring a class inside of main (it isn't needed and you never instantiate it)? And please align your braces as your code is difficult to read.

    Regards,
    Jim
    I don't understand what you mean when you said "align your braces". Please excuse me for not knowing what you are referring to. I'm taking an introductory course to Java for school and this was never mentioned. I know the braces you are talking about though. I looked in my Netbeans help section and I am not able to find it.

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: I can't figure out what is wrong

    I don't understand what you mean when you said "align your braces"
    Look at the code in post#5. The {}s are nicely aligned there. The }s are in the same column as the { they are paired with.
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    Join Date
    Dec 2015
    Posts
    9
    Rep Power
    0

    Default Re: I can't figure out what is wrong

    Quote Originally Posted by Norm View Post
    Look at the code in post#5. The {}s are nicely aligned there. The }s are in the same column as the { they are paired with.
    I think I'm doing okay except for maybe one or two hiccups.

    Line 29 in this one is giving me the error "Cannot find symbol. Symbol: variable input". I have a feeling that it is something so small and I can't find it since I have been working on this for days.


    Java Code:
    package classproject;
    
    import static jdk.nashorn.tools.ShellFunctions.input;
    
    /**
     *
     * @author James
     */
    public class ClassProject {
    
        private static int commission;
        
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args)
        {
            
            // TODO code application logic here
            
            System.out.println("the fixed salary is: $75000");
                    double earnings = 75000;
                    
                   
                    
                    
                    System.out.println("How much have you made in sales?");
                    int sales = input.nextDouble();
                    
                    double total = earnings + commission * sales;
                    
                     System.out.println("The total income that you made this year is: $" + total);
        }
        
    }

    Java Code:
    package classproject;
    
    import java.text.DecimalFormat;
    import java.util.Scanner;
    /**
     *
     * @author James
     */
    public class Week3 {
         public static void main(String[] args) {
            
            Week3 s=new Week3();
            DecimalFormat df=new DecimalFormat("0.00");
            double annualSales;
            System.out.println("Enter the total annual sales : ");
            Scanner in =new Scanner(System.in);
            annualSales=Double.parseDouble(in.nextLine());
            double extendedSales=annualSales+annualSales*0.5;
            System.out.println("Total Sales  " +"   Total Compensation");
            while(annualSales<=extendedSales)
            {
                 System.out.println("$"+annualSales+"         $"+df.format(s.totalCompensation(annualSales)));
                 annualSales+=5000;
            }
        }
    
        private Object totalCompensation(double annualSales)
        {

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: I can't figure out what is wrong

    "Cannot find symbol. Symbol: variable input"
    The compiler can not find a definition for the variable: input that is in scope where it is used.
    Where is that variable defined?
    It looks like it should be defined as a Scanner.
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: I can't figure out what is wrong

    Both of your classes have a main method. Are they separate assignments? Which class is causing the problem? In the first class, no Scanner is assigned to input.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  15. #15
    Join Date
    Dec 2015
    Posts
    9
    Rep Power
    0

    Default Re: I can't figure out what is wrong

    Yes they are separate assignments but they need to run as one program. The first class will need Scanner added to it which I am going to do right now.

  16. #16
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: I can't figure out what is wrong

    need to run as one program.
    What does that mean?
    Java programs start their execution in the main() method of a class.
    Which class do you want to be started with the java command?
    How will the code in the other class be executed?
    If you don't understand my response, don't ignore it, ask a question.

  17. #17
    Join Date
    Dec 2015
    Posts
    9
    Rep Power
    0

    Default Re: I can't figure out what is wrong

    Quote Originally Posted by Norm View Post
    What does that mean?
    Java programs start their execution in the main() method of a class.
    Which class do you want to be started with the java command?
    How will the code in the other class be executed?
    I see what you're saying. I can't have more than one main method to have all of the classes run together. Am I in the right direction? If so, I need to remove the main method from the second class.

  18. #18
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: I can't figure out what is wrong

    What you are trying to do is very common to OOP programming. You need to read up on how to create classes with methods that can be called from other methods to do tasks.
    You use that technique all the time. For example:
    Java Code:
            Scanner in =new Scanner(System.in);    // Create an instance of the Scanner class
            annualSales=Double.parseDouble(in.nextLine());   // call that class's nextLine() method
    If you don't understand my response, don't ignore it, ask a question.

  19. #19
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: I can't figure out what is wrong

    Quote Originally Posted by jameswinfield3 View Post
    I can't have more than one main method to have all of the classes run together. Am I in the right direction? If so, I need to remove the main method from the second class.
    Each of your classes may have a main entry point. But usually only one is used as the real start of the application so it is probably a good idea to remove one. In your case it was confusing. If you start the program choosing one of the other main entry points, then your program will probably fail during initialization.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  20. #20
    Join Date
    Dec 2015
    Posts
    9
    Rep Power
    0

    Default Re: I can't figure out what is wrong

    Quote Originally Posted by Norm View Post
    What you are trying to do is very common to OOP programming. You need to read up on how to create classes with methods that can be called from other methods to do tasks.
    You use that technique all the time. For example:
    Java Code:
            Scanner in =new Scanner(System.in);    // Create an instance of the Scanner class
            annualSales=Double.parseDouble(in.nextLine());   // call that class's nextLine() method

    I am looking into it right now. I really appreciate your help with this.

Page 1 of 2 12 LastLast

Similar Threads

  1. I need help cant figure out what's wrong
    By OmegaDracoMax in forum New To Java
    Replies: 4
    Last Post: 09-13-2012, 11:16 PM
  2. what is wrong with this? cant figure it out
    By flagrl in forum NetBeans
    Replies: 3
    Last Post: 01-27-2012, 01:10 AM
  3. Can't figure out what's wrong, help please.
    By Taszk in forum New To Java
    Replies: 30
    Last Post: 05-24-2011, 11:30 AM
  4. Cant figure out where went wrong.
    By leviathan in forum New To Java
    Replies: 15
    Last Post: 06-06-2010, 06:55 PM
  5. Replies: 2
    Last Post: 07-11-2008, 09:41 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •