Results 1 to 8 of 8
  1. #1
    MSD1964 is offline Member
    Join Date
    Jun 2012
    Posts
    4
    Rep Power
    0

    Default ArrayList issues

    I'm beating my head against a wall on this, I'm sure it's something simple that I just don't understand yet because I am new to java.

    Any help would be appreciated.

    I think there is an issue with the Double annualSales and the ArrayList, but I'm not sure.


    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package commission;

    import java.util.ArrayList;
    import java.util.Scanner;

    /**
    * * @author
    *
    * This program will calculate a sales persons annual sales commission plus fixed
    * salary based on a 5% commission staring at 80% of the 500,000 sales target.
    * Additionally the program will show the sales person what their commission
    * would have been had the achieved greater sales.
    */
    public class Commission
    {
    public static final int salesTarget = 500000; // Setting of Sales Target
    public static final float accelerationFactor = 0.075f; // rate accelerator
    public static final float minimumSales = 0.80f; // Commision starts at 80%

    public static void main(String[] args)
    {

    ArrayList <String> name = new ArrayList<String>();
    ArrayList <Double> annualSales = new ArrayList<Double>();


    Scanner input = new Scanner(System.in); // enables keyboard input

    System.out.println("Please enter Sales Person name") ;
    name.add(input.nextLine());

    // prompts user for name of sales person

    System.out.print("Please enter annual sales: ") ;//Prompts user for sales
    annualSales.add(input.nextDouble());

    SalesPerson salesPerson = new SalesPerson // enables salesPerson class
    (50000, .05, salesTarget, minimumSales); // set initial values

    System.out.println("Total Compensation: " //displays salary + commission
    + (salesPerson.totalCompensation(annualSales, minimumSales)));

    System.out.println(); // print blank line
    System.out.println("SalePerson\tTotal Sales\tTotal Compensation");//Print column names
    System.out.println(); // print blank line
    System.out.println((name) + "\t\t" + (annualSales) + "\t" + //print sales and compensation
    (salesPerson.totalCompensation(annualSales, minimumSales )));


    }
    }



    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    /** *
    * @author
    */
    class SalesPerson
    {
    //Variables set so they are only visable in the salesPerson class
    private double fixedSalary = 50000;
    private double commissionRate = .05;
    private double salesTarget = .80f;
    private float accelerationFactor = .075f;

    public SalesPerson // set the salesPerson instance with associated variables
    (double fixedSalary, double commissionRate,
    double salesTarget, float accelerationFactor)
    {
    this.fixedSalary = fixedSalary;
    this.commissionRate = commissionRate;
    this.salesTarget = salesTarget;
    this.accelerationFactor = accelerationFactor;
    }
    public double totalCompensation(double annualSales, double minimumSales)
    {
    // The following code determines the minimum sales in dollars and
    // susequently determines which level of commission incentive will
    // be awarded before finally calculating the total annual compensation.

    double minSalesCalc = salesTarget * minimumSales;

    // The following code compares the two variables and sets the variable
    // diff equal to 0 as a starting point for the calculations.

    int diff = Double.compare(annualSales,minSalesCalc);

    if(diff >= 0)
    { minSalesCalc = fixedSalary;
    if(annualSales > salesTarget)
    {
    minSalesCalc += salesTarget * commissionRate;
    minSalesCalc += (annualSales - salesTarget) * accelerationFactor;
    } else
    { minSalesCalc += annualSales * commissionRate;
    } return minSalesCalc;
    } else
    { return fixedSalary;
    }
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    MSD1964 is offline Member
    Join Date
    Jun 2012
    Posts
    4
    Rep Power
    0

    Default Re: ArrayList issues

    Sorry, here is the error I get when running.

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>
    at commission.Commission.main(Commission.java:44)

    System.out.println("Total Compensation: " //displays salary + commission
    + (salesPerson.totalCompensation(annualSales, minimumSales)));

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: ArrayList issues

    You're trying to run a Java program that can't be compiled -- something that should never be done. You will want to try to compile it first, and then report to us any compilation errors.

  5. #5
    MSD1964 is offline Member
    Join Date
    Jun 2012
    Posts
    4
    Rep Power
    0

    Default Re: ArrayList issues

    Does this help?

    String totalCompensation(ArrayList<Double> annualSales, float minimumSales) {
    throw new UnsupportedOperationException("Not yet implemented");


    method totalCompensation in class commission.SalesPerson cannot be applied to given types;
    required: double,double
    found: java.util.ArrayList<java.lang.Double>,float
    reason: actual argument java.util.ArrayList<java.lang.Double> cannot be converted to double by method invocation conversion
    ----

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: ArrayList issues

    The main problem that the error is pointing out is that your method's first parameter should be a double, and you're passing in an ArrayList of Double, which doesn't make sense to the compiler (or to me).

    Why are you using ArrayLists in this program when you're only getting one Saleperson's worth of data? And if you eventually need to create more than one Salesperson, why not create an ArrayList of these guys -- ArrayList<SalesPerson>. Also, don't use float but rather doubles as the accuracy of double is much greater than that of float. If you were really doing financial calculations, you wouldn't even be using doubles but rather BigDecimal.

  7. #7
    MSD1964 is offline Member
    Join Date
    Jun 2012
    Posts
    4
    Rep Power
    0

    Default Re: ArrayList issues

    Quote Originally Posted by Fubarable View Post
    The main problem that the error is pointing out is that your method's first parameter should be a double, and you're passing in an ArrayList of Double, which doesn't make sense to the compiler (or to me).

    Why are you using ArrayLists in this program when you're only getting one Saleperson's worth of data? And if you eventually need to create more than one Salesperson, why not create an ArrayList of these guys -- ArrayList<SalesPerson>. Also, don't use float but rather doubles as the accuracy of double is much greater than that of float. If you were really doing financial calculations, you wouldn't even be using doubles but rather BigDecimal.
    No real reason to use ArrayList other than not knowing better, so I removed the Arraylist declare and consturction and replaced them with two simple arrays. But that didn't help

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: ArrayList issues

    Quote Originally Posted by MSD1964 View Post
    No real reason to use ArrayList other than not knowing better, so I removed the Arraylist declare and consturction and replaced them with two simple arrays. But that didn't help
    I know this must be frustrating for you. To have us be able to help you though, you must give us specific, not general information: please show your latest code attempt and any new error messages. Please use [code] [/code] tags around your code so that it will retain its formatting.

Similar Threads

  1. Replies: 12
    Last Post: 07-07-2011, 09:49 PM
  2. Replies: 4
    Last Post: 06-02-2011, 11:15 PM
  3. sorting arraylist based on another arraylist
    By busdude in forum New To Java
    Replies: 4
    Last Post: 02-07-2011, 12:48 PM
  4. Replies: 7
    Last Post: 11-22-2010, 02:26 PM
  5. Replies: 2
    Last Post: 04-21-2008, 12:43 PM

Posting Permissions

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