Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

Can someone help me get my Table.java file to work with my AnnualCompensation.java file?

Nelson Nolan
Greenhorn
Posts: 1
I have an assignment that's due today in about 13 hours, I have completed everything that's required by the assignment, however now my table doesn't work which is in a seperate class file. The table technically isn't needed, however I want to keep it but don't know how to get it to work with the new information in my files.

What I need is for this table to somehow work with my array. The table needs to take the information that is input by the user in AnnualSales[0], and AnnualSales[1] and display in increments of \$5,000 from \$120,000 - \$180,000 if the sales person made less than \$120,000. If the Sales Person made more than \$120,000 the table needs to show in increments of \$5,000 up from what the sales person made in annual sales up to 1.5 times the amount they made. If they make over \$96,000 which is 80% of \$120,000 they will get a 5% commission of the sales. If they make over \$120,000 they will get an added 1.5% acceleration rate added to the 5% commission to make it 6.5% total after \$120,000.

The table will increment basically what they would have made if they had made \$5,000 more than what they made up to 1.5 times the amount they made. On \$120,000 the table will go up to \$180,000 in increments of say \$120,000, \$125,000, \$130,000, \$135,000 - \$180,000 which is 1.5 times the \$120,000. Can someone help me to recode this so that it works properly in my coding.

Table.java is the file that i'm using for my table. AnnualCompensation.java is the file that it needs to work with. They are both in my package called "SimpleCommission". I will post the coding for both in this question:

AnnualCompensation.java

package SimpleCommission;

// This allows for user input.
import java.util.Scanner;

public class AnnualCompensation // Created class AnnualCompensation.
{ // Starts the class AnnualCompensation body

public static void main(String[] args) // Creates a method called main.
{ // Starts the body of the main method.

// This creates variables to store information.
double Salary;
double Sales;
double Commission;
double Bonus;
double AnnualCompensation;
Salary = 75000; // Sets the salary to a fixed \$75,000.

String[] SalesPerson = new String[2]; // Creates an array using a string.
int[] AnnualSales = new int[2]; // Creates an array using an integer.

// Activates the user input allowing for input to be used to get information.
Scanner input = new Scanner(System.in);

// Asks the user to input the name of the 1st Sales Person.
System.out.println("What's the 1st Sales Person's Name?");
SalesPerson[0] = input.nextLine();

// Asks the user to input the name of the 2nd Sales Person.
System.out.println("What's the 2nd Sales Person's Name?");
SalesPerson[1] = input.nextLine();

// Asks the user to input the annual sales for the 1st Sales Person.
System.out.println("What's the 1st Sales Person's Annual Sales?");
AnnualSales[0] = input.nextInt();

// Asks the user to input the annual sales for the 2nd Sales Person.
System.out.println("What's the 2nd Sales person's Annual Sales?");
AnnualSales[1] = input.nextInt();

// Creates a variable to store information.
double Total;

// Sets the program to respond if the input for AnnualSales[0] is less
// Than the input for AnnualSales[1].
if(AnnualSales[0] < AnnualSales[1])
{
// Prints out the 1st & 2nd Sales Person's name's.
System.out.println("\n" + SalesPerson[0] + "\t" + "\t" + SalesPerson[1]);

// Subtracts the input for AnnualSales[0] from the input for
// AnnualSales[1] to show the amount necessary to be equal.
Total = (AnnualSales[1] - AnnualSales[0]);

// Prints out the total amount of annual sales for Sales Person 1 & 2.
System.out.println(AnnualSales[0] + "\t" + "\t" + AnnualSales[1]);

// Prints out the amount Sales Person 1 would need to Sell in order to
// have sold the same amount as Sales Person 2.
System.out.println(SalesPerson[0] + " needs to sell " + Total
+" To equal the amount " + SalesPerson[1] + " Sold.");
}

// Sets the program to respond if the input for AnnualSales[1] is less
// Than the input for AnnualSales[0].
if(AnnualSales[1] < AnnualSales[0])
{
// Prints out the 1st & 2nd Sales Person's name's.
System.out.println("\n" + SalesPerson[0] + "\t" + "\t" + SalesPerson[1]);

// Subracts the input for AnnualSales[1] from the input for
// AnnualSales[0] to show the amount necessary to be equal.
Total = (AnnualSales[0] - AnnualSales[1]);

// Prints out the total amount of annual sales for Sales Person 1 & 2.
System.out.println(AnnualSales[0] + "\t" + "\t" + AnnualSales[1]);

// Prints out the amount Sales Person 2 would need to Sell in order to
// have sold the same amount as Sales Person 1.
System.out.println(SalesPerson[1] + " needs to sell " + Total
+" To equal the amount " + SalesPerson[0] + " Sold.");
}
// If the amounts don't equal the above else is used to show that the amounts are equal
// to each other and displays seperate information.
else
{
// Allows the information to be compared and if AnnualSales[0] is equal to
// AnnualSales[1] this part of the program runs.
if(AnnualSales[0] == AnnualSales[1])
{
// Prints the name's of Sales Person 1 & Sales Person 2.
System.out.println("\n" + SalesPerson[0] + "\t" + "\t" + SalesPerson[1]);

// Prints out the amount of Annual Sales for Sales Person 1 & Sales Person 2.
System.out.println(AnnualSales[0] + "\t" + "\t" + AnnualSales[1]
+ "\n" + SalesPerson[0] + " & " + SalesPerson[1]
+ " Sold the same amount.");

}
}
if(AnnualSales[0] >= 96000) // Runs if Annual Sales are over \$96,000 otherwise is skipped.
{ // Starts the body of the if clause.
Commission = (AnnualSales[0] * .05); // Sets the value of Commission to 5%.

// Prints out the total amount of commission.
System.out.println("For " + SalesPerson[0] + " The total commission is: \$"
+ Commission);

if(AnnualSales[0] >= 120000) // Nested if clause only runs if Annual Sales are over \$120,000
{ // Starts the body of the nested if clause.

Bonus = (AnnualSales[0] * .015); // Sets the value of Bonus to 1.5%.

// Prints out the total amount of the Bonus.
System.out.println(SalesPerson[0] + " reached the sales target of "
+ "\$120,000");

// Sets Annual Compensation to total of Salary, Commission, & Bonus all together.
AnnualCompensation = (Bonus + Commission + Salary);

// Prints out the amount of Annual Compensation.
System.out.println("The total annual compensation for " + SalesPerson[0]
+ " is: \$" + AnnualCompensation );
} // Ends the body of the nested if clause.

else // Creates a nested else clause which only runs if the nested if is skipped.
{ // Starts the body of the nested else clause.

//Prints that the salesperson didn't get the incentive bonus.
System.out.println(SalesPerson[0] + " didn't meet the sales target "
+ "& doesn't get a bonus.");

// To calculate the total yearly compensation without the bonus

// Sets Annual Compensation to total of Fixed Salary & Commission together.
AnnualCompensation = (Salary + Commission);

// Prints the amount of Annual Compensation.
System.out.println("The total annual compensation for "
+ SalesPerson[0] + " is: \$" + AnnualCompensation );
} // Ends the body of the nested else clause
} // Ends the body of the if clause.

else // Creates an else clause which only runs if the if clause is skipped.
{ // Starts the body of the else clause

// Prints that the Salesperson didn't reach 80% of the Sales Target
System.out.println(SalesPerson[0] + " didn't meet 80% of Sales Target "
+ "so there is no extra commission or bonus. ");

// Sets the Annual Compensation to the amount of the Fixed Salary.
AnnualCompensation = Salary;

// Prints the amount of Annual Compensation without the commission & bonus.
System.out.println("The total annual compensation for " + SalesPerson[0] +
" is: \$" + AnnualCompensation );
} // Ends the body of the else clause.

if(AnnualSales[1] >= 96000) // Runs if Annual Sales are over \$96,000 otherwise is skipped.
{ // Starts the body of the if clause.

Commission = (AnnualSales[1] * .05); // Sets the value of Commission to 5%.

// Prints out the total amount of commission.
System.out.println("For " + SalesPerson[1] + " The total commission is: \$"
+ Commission);

if(AnnualSales[1] >= 120000) // Nested if clause only runs if Annual Sales are over \$120,000
{ // Starts the body of the nested if clause.

Bonus = (AnnualSales[1] * .015); // Sets the value of Bonus to 1.5%.

// Prints out the total amount of the Bonus.
System.out.println(SalesPerson[1] + " reached the sales target of "
+ "\$120,000");

// Sets Annual Compensation to total of Salary, Commission, & Bonus all together.
AnnualCompensation = (Bonus + Commission + Salary);

// Prints out the amount of Annual Compensation.
System.out.println("The total annual compensation for " + SalesPerson[1] +
" is: \$" + AnnualCompensation );
} // Ends the body of the nested if clause.
else // Creates a nested else clause which only runs if the nested if is skipped.
{ // Starts the body of the nested else clause.

//Prints that the salesperson didn't get the incentive bonus.
System.out.println(SalesPerson[1] + " didn't meet the sales target "
+ "& doesn't get a bonus.");

// To calculate the total yearly compensation without the bonus

// Sets Annual Compensation to total of Fixed Salary & Commission together.
AnnualCompensation = (Salary + Commission);

// Prints the amount of Annual Compensation.
System.out.println("The total annual compensation for " + SalesPerson[1] +
" is: \$" + AnnualCompensation );
} // Ends the body of the nested else clause
} // Ends the body of the if clause.
else // Creates an else clause which only runs if the if clause is skipped.
{ // Starts the body of the else clause

// Prints that the Salesperson didn't reach 80% of the Sales Target
System.out.println(SalesPerson[1] + " didn't meet 80% of Sales Target "
+ "so there is no extra commission or bonus. ");

// Sets the Annual Compensation to the amount of the Fixed Salary.
AnnualCompensation = Salary;

// Prints the amount of Annual Compensation without the commission & bonus.
System.out.println("The total annual compensation for " + SalesPerson[1] +
" is: \$" + AnnualCompensation );

} // Ends the body of the else clause.
Table Table = new Table();
Table.CompTable();
} // Ends the main method of Trial Class.
} // Ends the Trial class.

Table.java

package SimpleCommission;

public class Table // Creates the class Table.
{ // Starts the body of the class Table

public void CompTable() // Creates method CompTable.
{ // Starts the body of the CompTable method.

//Prints out what this table is for.
System.out.println("This Is The Potential Total Annual Compensation "
+ "That The Salesperson Could Have Made:");

double Sales = 120000; //Sets the Sales total to \$120,000.
double Max = Sales * 1.50; //Sets the max total this while loop will run to.

/**********************************************************************
* Below is the while loop being used to bring the table of what the *
* salesperson would potentially make at each amount in increments of *
* \$5,000 starting at the annual sales total of \$120,000 and going to *
* 50% above the salesperson's annual sales. *
*********************************************************************/

while(Sales <= Max) //This sets the while loop to start at minimum & end at the max
{ // This starts the body of the while loop.

//This sets the Incentive rate's to progress in the table properly.
double Incentive = Sales * 0.065;

//This prints out a line for each of the levels of annual sales & incentives.
System.out.println("For: \$" + Sales
+ " The incentive is: \$" + Incentive);

//This sets the sales to increase +\$5,000 each time the while loop runs so that it
//progresses and stops at the max which is 50% above the \$120,000 annual sales.
Sales = Sales + 5000;
} //Ends the body of the while loop.
} //Ends the body of CompTable method.
} //Ends the body of the class Table

Now this is the assignment details, as you can see this isn't part of the assignment, however i'd like help figuring this out for future knowledge to help me understand Java better for my own benefit. Here is the assignment details:

Individual Write a simple commission calculation program using IDE.
* Modify the Week Three Java™ application using Java™ 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.

So if someone can help me out with this ASAP it would be greatly appreciated, i'm really having problems getting this to work in my other class and adjust to the amount entered. Thanks in advance.

harshvardhan ojha
Ranch Hand
Posts: 157
1

harshvardhan ojha
Ranch Hand
Posts: 157
1
As far i have understood your code, it seems that you have coded it in FP way as you have been told about.
Object oriented flavour is definetely missing from your design. So design your problem well.

Also keep method for calculations.

proper documentation doesn't mean lot. keep method level comments in
/**
*
*/ comments, explain what input is expected, what is the output someone can expect out of your methos, and provide comments for logic only when needed.

Hope to see your better design soon.

Kemal Sokolovic
Bartender
Posts: 825
5

Welcome to the Ranch!

jeff cantrell
Ranch Hand
Posts: 38
I have almost the same problem can someone help me with it i can post the info if anyone can help me with it please?

Bartender
Posts: 1499
14