ok Here is where I am now. I had the code written and it displayed correctly as long as salesPerson1 was the highest earner. I added the additional code if total2 > total1 and so on and now I do not get the calculations just display total commission of 1,2, and 3. I tried posting my code but it is too long. I am going to try to start with a new question and see if I can post it there. I need to calculate the additional amount of sales each salesperson must achieve to match or exceed the highest earner.
Here's my code
package Commission3;
import java.util.Scanner;
public static void main(String[] args) {
// Creat a new object AnnualCompensation
AnnualCompensation salesPerson[] = new AnnualCompensation[3];
// creat three object
salesPerson[0] = new AnnualCompensation();
salesPerson[1] = new AnnualCompensation();
salesPerson[2] = new AnnualCompensation();
//new scanner input
Scanner keyboard = new Scanner(System.in);
//get salesperson1 name
System.out.println("What is your first salesperson's name?");
salesPerson[0].name = keyboard.nextLine();
//get salesperson1 sales total
System.out.println("Enter annual sales of first salesperson: ");
double val = keyboard.nextDouble();
salesPerson[0].setAnnualSales(val);
//get salesperson2 name
System.out.println("What is your second salesperson's name?");
salesPerson[1].name = keyboard.next();
//get salesperson2 sales total
System.out.println("Enter annual sales of second salesperson: ");
val = keyboard.nextDouble();
salesPerson[1].setAnnualSales(val);
//get salesperson3 name
System.out.println("What is the name of your third salesperson?: ");
salesPerson[2].name = keyboard.next();
//get salesperson3 sales total
System.out.println("Enter annual sales of third salesperon: ");
val = keyboard.nextDouble();
salesPerson[2].setAnnualSales(val);
double total1, total2, total3;
total1 = salesPerson[0].getTotalSales();
System.out.println("Total sales of " + salesPerson[0].name +" is: $" + total1);
total2 = salesPerson[1].getTotalSales();
System.out.println("Total sales of " + salesPerson[1].name +" is: $" + total2);
total3 = salesPerson[2].getTotalSales();
System.out.println("Total sales of " + salesPerson[2].name +" is: $" + total3);
if (total1 > total2) {
System.out.print("Salesperson " + salesPerson[1].name + "'s additional amount of sales that he must " + " achieve to match or exceed the higher of the salesperson " + salesPerson[0].name);
System.out.println(" $" + (total1 - total2));
if (total1 > total3) {
System.out.print("Salesperson " + salesPerson[2].name + "'s additional amount of sales that must " + " be achieved to match or exceed the higher of the salesperson " + salesPerson[0].name);
System.out.println(" $" + (total1 - total3));
if (total2 > total1){
System.out.println("Salesperson" + salesPerson[1].name + "'s additional amount of sales that must " + " be acheived to match or exceed the higher of the salesperson " + salesPerson[2].name);
System.out.println(" $" + (total2 - total1));
if (total2 > total3){
System.out.println("Salesperson" + salesPerson[3].name + "'s additional amount of sales that must " + " be acheived to match or exceed the higher of the salesperson " + salesPerson[2].name);
System.out.println(" $" + (total2 - total3));
if (total3 > total1){
System.out.println("Salesperson" + salesPerson[1].name + "'s additional amount of sales that must " + " be acheived to match or exceed the higher of the salesperson " + salesPerson[3].name);
System.out.println(" $" + (total3 - total1));
if (total3 > total2){
System.out.println("Salesperson" + salesPerson[2].name + "'s additional amount of sales that must " + " be acheived to match or exceed the higher of the salesperson " + salesPerson[3].name);
System.out.println(" $" + (total2 - total3));
} else if (total2 > total1) {
System.out.print("Salesperson " + salesPerson[0].name + "'s additional amount of sales that must " + " be achieved to match or exceed the higher of the salesperson " + salesPerson[1].name);
System.out.println(" $" + (total2 - total1));
}
else {
System.out.println("Both have same compensation $" + total1);
}
}
}
}