Sales comparision using arrays or arrayList

homework
java

#1

All, I am attempting to work through a java programming class and this is all new to me. So, I am saying I do not know what I am doing. Below is my assignment and coding:
Modify the Week Three Java application using NetBeans IDE to meet these additional and changed business requirements:
•The application will now compare the total annual compensation of at least two salespersons.
•It will calculate the additional amount of sales that each salesperson must achieve to match or exceed the higher of the two earners.
•The application should ask for the name of each salesperson being compared.

The Java application should also meet these technical requirements:
•The application should have at least one class, in addition to the application’s controlling class.
•The source code must demonstrate the use of Array or ArrayList.
•There should be proper documentation in the source 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 commissiongenerator;

import java.util.*; // needed for Scanner and 2nd precedent
import java.util.Scanner; 
/**
 *
 * @author Bonita Anderson
 */
public class CommissionGeneratorApp {
 public static void main(String args[], int i) {
      String[] Salesperson = {"Bonita Anderson", "Florence Davis"};
     double annualSales;
        CommissionGenerator person;
        Scanner input=new Scanner(System.in);
        System.out.print(Salesperson[0]);
        System.out.print("Please enter your total sales for the year: ");
        annualSales=input.nextDouble();
        System.out.print(Salesperson[01]);
        System.out.print("Enter annual salary for Florence Davis: ");
        annualSales=input.nextDouble();
        person=new CommissionGenerator(annualSales);
        System.out.println(" Your total annual sales for the year: $"+String.format("%.2f", person.getTotalAnnualSales()));

        System.out.println("Total Sales              Total Compensation");

I need to add my if statement to say if saleperson1 annual salary > salesperson2 annual salary earn amount = salesperson1 annual salary - salesperson 2 annual salary, if salesperson1 annual salary = salesperson 2 annual salary earn amount = 0, if salesperson1 annual salary < salesperson2 earned amount = salesperson2 - salesperson2.

I hope this makes sense. Can someone help…


#2
person=new CommissionGenerator(annualSales);

you didn’t provide CommissionGenerator, so i can only guess what it does

If you want help, please provide a way for us to run a duplicate of your project, so we can actually help you.

if you need to add this, what help do you desire of us?


#3

Okay new at this. I will post

Bonita


#4

I have worked on this and changed some of the coding. I am pasting both files for you to attempt to run. I have an error with the for statement and from what I know it should work. So I cannot proceed with the coding.
— CommissionGenerator

package commissiongenerator;
/*use this to calculate
 * This program is to address a salesperson will continue to earn a fixed salary of $120,000. 
 * The current sales target for every salesperson is $500,000.
 * salesperson must meet 80% of target to earn a commission
 * if sales exceeds target salesperson will receive .075 commission of sales
 */

import java.util.Scanner;
import java.text.NumberFormat;// need to format number as currency
import java.util.List;



public class CommissionGenerator {
// 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 CommissionGenerator(double annualSales){
     this.annualSales=annualSales;
     target=500000;
     commission=0;
     annualSales = 0;
	 
     if (annualSales<target*0.8)commission=0.00;
     if(annualSales==target*0.8)commission=0.06*annualSales;{
        if(annualSales>target*0.8)commission=0.0725*annualSales;
     
        
     }
     fixedSalary=120000;
 }
 public double getTotalAnnualCompensation(){// calculate The total annual compensation is the fixed salary plus the commission earned
     return fixedSalary+commission;
 }
     public double getTotalAnnualSales(){
         return annualSales;
     }
 }

–CommissionGeneratorApp

/* this file uses for the input for the user
 * 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 commissiongenerator;
import java.util.Scanner;
import java.util.*; // needed for Scanner and 2nd precedent

/**
 *
 * @author Bonita Anderson
 */
public class CommissionGeneratorApp {
    Scanner input = new Scanner(System.in);
 public static void main(String args[])
      
        
 {

   double annualSales =0;
        CommissionGenerator person;
        Scanner input=new Scanner(System.in);
        ArrayList<CommissionGenerator> array = new ArrayList<CommissionGenerator>();
        String[] name = new String [] {"Bonita Anderson", "Florence Davis"};
        for (int i = 0; i < name.length; 1++)

The output should show the following:
Bonita Anderson total sales (based on user input) and total compensation (based on controlling file if statement)
Florence Davis total sales and total compensation
Next, I will need to write coding to show the difference between the highest and lowest of the two. For ex: Bonita total sales 400000.00 and Florence 350000.00 then Florence needs to earn 50000.00 more sales to meet Bonita’s sales.


#5

then there is a small gap in your knowledge, 1++? You know what ++ does right? It increases a variable by one, what you wrote is:

1 = 1 + 1

in other words, one equals two. Good math

You would want to increase i (that is the letter i of indigo)


#6

I have corrected. Now I need to understand why my system output language is not working to pull the name, sales, and total compensation of the input.
Below is the coding:

/*
 * 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 comparesalespersons;

/**
 *
 * @author Bonita Anderson
 */
public class CalculatedCompensation {
  //method to calculate annual compensation  

    public double calculation(double total_sales) {  

         double fixed_salary = 120000, //fixed salary of $120,000.00 per year  

                sales_target = 500000, //sales target is $500,000.00 per year  

                incentive_rate = 0.8, // sales incentive start when 80% of the sales target is met  

                 commission_rate = 0.06, //current commission is 6% of total sales  

                acceleration = 1.25, //acceleration factor is 1.25  

                 compensation = 0; //Total compensation  

   

         //If total sales is less than 80% of sales target  

         if (total_sales < (sales_target * incentive_rate)) {  

             compensation = fixed_salary;  

         } //If total sales meet 80% of the sales target  

        else if (total_sales <= sales_target) {  

            compensation = fixed_salary + (total_sales * commission_rate);  

         } //If total sales exceed the sales target  

         else if (total_sales > sales_target) {  

             compensation = fixed_salary + (total_sales * commission_rate * acceleration);  

         }  

    

         return compensation;  

     }  

    

     // mothod to find the highest earner  

     // take array of compensation and its size as parameter  

     public int highest_earner(double[] compensation_array, int size) {  

         int index = 0; // index of highest earner in array  

         double max = 0; 
         
        
         // loop all array and find highest earner  

         for (int i = 0; i < size; i++) {  

             if (compensation_array[i] > max) {  

                max = compensation_array[i];  

                index = i;  

             }  

         }  

         return index;  

     }  

 }

/*
 * 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 comparesalespersons;
import java.util.Scanner;
/**
 *
 * @author Bonita Anderson
 */
public class Comparesalespersons {
                Comparesalespersons person;
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in); // for user input  

         //create new object to compute compensation and  find the highest earner  

         CalculatedCompensation a = new CalculatedCompensation();  

         // ask user enter number of salespersons  

         System.out.print("How many salespersons do you want to compare: ");  

        int SIZE = input.nextInt();  

         // create an array to store names of salespersons  

         String[] name = new String[SIZE];  

        // create an array to store annual sale of salespersons  

         double[] sale = new double[SIZE];  

         // create an array to store total compensation of salespersons  

        double[] compensation = new double[SIZE];  
        //CalculatedCompensation person;
           

         // input data for each person and compute compensation for that one  

         for (int i = 0; i < SIZE; i++)   

        {  

             input.nextLine();  

             System.out.print("Please enter name of person " + (i+1) + ": ");  

             name[i] = input.nextLine();             

             System.out.print("Please enter total annual sales of person " + (i+1) + ":  $");  

             sale[i] = input.nextDouble(); 
             
                   
            compensation[i] = a.calculation(sale[i]); 
           
            
  
        
           
          // display both sales person's total sales and total compensation
         System.out.print("Name          Total Sales      and Total Compensation: \n" + name + total_sales + compensation) "; ");
           
           
           
           
           
        } 

         // find index of the highest earner in array  

         int highest = a.highest_earner(compensation, SIZE);  

        
         
// display the highest earner  
         System.out.println("\nThe highest earner is: \n" + name[highest] +   

                            " with total sales: $" + sale[highest] +  

                            " and total compensation: $" + compensation[highest]);  

            

         // calculate and display the additional amount of sales that each salesperson   

         // must achieve to match or exceed the higher of the two earners  

         System.out.println("\nAdditional amount of sales needed for others to match the higgest earners:");  

         System.out.format("%-25s%10s\n", "   Name", "Sale amount needed");  
           
       
                
         for (int i = 0; i<SIZE; i++)  

        {  

             if (i==highest) {  

                 continue;  

             } // skip the highest earner  

             //System.out.println(name[i] + "\t\t$" + (sale[highest] - sale[i]));  

             System.out.format("%-25s%10s\n", name[i], (sale[highest] - sale[i])); 
             
             
            

                

                

         }  

    }
}

#7

Let me stop you there, this is not how it works. You asked a question, i answered it.

This are different files of a different package. I am not someone you can just endlessly ask questions to. If you still have questions, you can make a new topic.

Here is one last hint, in my case the IDE throws an error for this line:

System.out.print("Name          Total Sales      and Total Compensation: \n" + name + total_sales + compensation) "; ");

if you read the error thrown by the IDE, that helps (total_sales is undefined)

Please read the guidelines on this matter.

There is not even a thank you for helping, a little grace goes a long way


#8