Hi, I am currently working on a java program for class and I cannot figure out what I am doing wrong. Each week I have been creating this java program that calculates sales, total compensation, etc. Well for my final team assignment my group has to take a piece of someone's program and replace it with someone else's and make it work. We have gotten the program to where it will ask for the persons name and the sales that person had. Well after that it should compare the 2 individuals and display the total sales, highest sales, and then "the salesperson with the lower compensation must increase their sales by the minimum of $" Well the total sales, highest sales and salesperson with lower compensation .... is appearing with all zero's. I don't know what is wrong with the code that is making it appear as $0.00
Here is the code:
//establishing the package the program will be under
import java.text.DecimalFormat;
import java.util.Scanner;
//This establishes that we will need an input from the keyboard
public class Assignment5W5
//The program is establishing what the class will be called
{
public static void main(String[]args)
//This establishes that this is the main controlling program.
{
//---------------------------------------------------------------------------------------------------
String [] thename = new String[10];
int arrnum = 0;
//Creating an array for the salespersons names, and establishing the counter at 0.
double [] thenumber = new double[10];
//Creating an array for the sales of the saleperson.
Scanner input = new Scanner(System.in);
//Calling input as the variable that the user will enter values
//---------------------------------------------------------------------------------------------------
//Using the class SalesPerson to establish the names of the salesperson.
SalesPerson salepername = new SalesPerson();
//Creates object salepername
arrnum = 1;
//Setting the array at the number 1 so the number of the sales person is established
//when the question is asked to enter the name.
while (arrnum <= 2 )
//The loop is based on the numbers in the array.
{
System.out.printf("what is the full name of salesperson %s\n",arrnum);
String salesname = input.nextLine();
//Taking in the sales persons name
salepername.setSalesname(salesname);
//Assinging the name of the salesperson in SalesPerson.java
thename[arrnum] = salesname;
//Placing the name in the array
arrnum = arrnum + 1;
//Adding 1 to the counter.
}
//---------------------------------------------------------------------------------------------------
//Using the class Sales to establish the sales of the salesperson.
Sales number = new Sales();
//Creates object number
arrnum = 1;
//Reseting the counter.
while (arrnum <=2)
//The loop is based on the numbers in the array.
{
System.out.println();
System.out.printf("What were the sales of %s\n", thename[arrnum]);
//Print out of the salespersons name and the entry number.
double salesnumber = input.nextDouble();
//Taking in the sales of the salesperson in the print line.
number.setSalesnumber(salesnumber);
//Assigning the sales of the salesperson in Sales.java
thenumber[arrnum] = salesnumber;
//placing the sales into the array.
arrnum = arrnum + 1;
//Adding 1 to the counter.
}
//---------------------------------------------------------------------------------------------------
//Calculations to get the sales numbers.
double num;
double num2;
double total;
//Variables needed for calculations.
num2 = thenumber[1];
num = thenumber[2];
//Setting the variables to the numbers in the array
if (num2 <= num)
//Conditional statement that compares the two numbers. The higher of the two numbers
//will be subtracted by the lower number. It is done this way to eliminate the
//negative number.
{
total = num - num2;
//Calculation to come up with the difference between the 2 salespeople.
System.out.printf(thename[1]+" is $%.2f", total);
System.out.printf(" short of "+thename[2]);
//Printing out the salespersons name that is lower than the other salesperson
//and by how much.
System.out.println();
//Spacing
}
else
{
total = num2 - num;
//Calculation to come up with the difference between the 2 salespeople.
System.out.printf(thename[2]+" is $%.2f", total);
System.out.printf(" short of "+thename[1]);
//Printing out the salespersons name that is lower than the other salesperson
//and by how much.
System.out.println();
//Spacing
}
final int ANNUAL_COMPENSATION = 2; // Number of array elements
// Create an array to hold the sales numbers per year.
double[] sales2 = new double[ANNUAL_COMPENSATION];
// Get the annual compensation and store it
// in the sales array.
//SalesData it = new SalesData(sales2);
// Create a SalesData object initialized with the
// sales array.
SalesData year = new SalesData(sales2);
// Create a DecimalFormat object for output formatting.
DecimalFormat dollar = new DecimalFormat("#,##0.00");
// Display the highest
// sales amounts for the year.
System.out.println();
System.out.println("The totals sales were $"
+ dollar.format(year.getTotals()));
System.out.println("The highest sales were $"
+ dollar.format(year.getHighest()));
System.out.println("The salesperson with the lower compensation must increase their sales by the minimum of $"
+ dollar.format(year.getHighest()-(year.getLowest())));
}
}
** And this is the end result:**
run:
what is the full name of salesperson 1
Bob
what is the full name of salesperson 2
Sally
What were the sales of Bob
321654
What were the sales of Sally
123456
Sally is $198198.00 short of Bob
The totals sales were $0.00
The highest sales were $0.00
The salesperson with the lower compensation must increase their sales by the minimum of $0.00
BUILD SUCCESSFUL (total time: 15 seconds)
Any help would be great! Thank you!
~Lindsey