How to Write Code in Two Programms

2021-04-27
3 pages
776 words
University/College: 
Type of paper: 
Essay
logo_disclaimer
This essay has been submitted by a student.
This is not an example of the work written by our professional essay writers.

Selecting the programs depends on the functionality of the program. Basically, these programs aim to give a solution to computation of sales person compensation on annual basis. Before writing the program, it is important to take note that of solution will apply mathematical concepts and functions. The classes in the program need to be defined using functions that can be manipulated mathematically. For instance, the code makes use of doubles since they can be manipulated mathematically.

Trust banner

If this sample essay on"How to Write Code in Two Programms" doesn’t help,
our writers will!

The Process of Identifying the Classes or Functions for Replacement

Changes can also be easily made in the two programs in terms of naming the variables and classes; changing the variables and classes does not really affect the code that much. There are also different ways of solving the problem in the two codes, for instance, in the first Sales Person code compensation is calculated by first determining the incentives of the sales person will receive then adding it to the fixed salary at the end. This change in the second program, where the total compensation is calculated at after testing each of the annual sales conditions in the loop. The Sales Person Annual Compensation code also differs in both programs. In the first program, there is assigning of currency units hence the requirement of importing libraries java.util.Locale and java.text.NumberFormat. Therefore, when selecting the two programs, the programs needed to portray different ways of solving the same problem yet they could be easily manipulated to achieve the task at hand.

In the first program, there were some classes and functions that are not really necessary. Looking at the Sales Person Annual Compensation code, you find that class getCurrencyInstance() is not really necessary nor is the specification (Locale.US). This line of code gives the salesperson compensation currency terms for data representation. However this can be and has been omitted in the second program which employs a more direct approach of solving the problem; that is, it does not first assign the compensation any currency value but rather gets the required information from the array list. This accounts for why the java.util.Locale and java.text.NumberFormat libraries are not utilized in the second program. The methods within the do while loop, however, forms the essential part of the program and hence remain unchanged in both of the codes. The array list library and scanner library also remain unchanged as the classes are required in data entry and enable one to ask for annual sales for a specific sales person.

In the computing the compensation in the two programs two different approaches has been employed right from the moment we initialize the variables. In the first code we have:

double fixedCompensation = 75000;

double commissionRate;

double salesTarget = 140000;

double salesNeededForIncentive = .80 * salesTarget;

double accelerator = 1.25;

double baseCommissionRate = .25;

double annualSales;

String SalesPersonName;

While in the second code

double salary = 75000;

double rate = .25;

double annual;

double compensation;

double target = 140000;

double acclerator = 1.25;

double minimumsales = 0.8;

double salesCalculator = minimumsales * target;

String SalesPName;

In the first code, the minimum sales required for incentives are calculated directly in one of the variables. In the second code, the minimum sales for incentives are calculated using a variable that represents the minimum sales rate and the target sales for the agents.

The Changes Needed to Make the Final Java Application Program Work Correctly

Having looked at the two codes for calculating the sales persons commission the one developed in the week four program is quite functional as it covers all the aspects needed to compute the compensation for the sales person. This is accomplished by looking at the different criteria for awarding compensation. However for the program to work more efficient, it would be advisable to create another double for outputting the total compensation. In the line of code return fixedCompensation + (annualSales * commissionRate) it is better if an double is used to as a return value. For instance we can use double TotalCompensation. Therefore when initializing our variables, we would have:

double fixedCompensation = 75000;

double commissionRate;

double salesTarget = 140000;

double salesNeededForIncentive = .80 * salesTarget;

double accelerator = 1.25;

double baseCommissionRate = .25;

double annualSales;

String SalesPersonName;

double compensation; // new variable

The result of the if else code will therefore be;

TotalCompensation = fixedCompensation + (annualSales * commissionRate);

Return TotalCompensation;

The second code has catered for these adjustments by use of double compensation which is a combination of the fixed salary and the incentives. Using the double compensation, the total amount of cash the sales person would receive at the end is computed depending on the whether the annual sale of the salesperson meet the conditions in if else loop.

To conclude, the two programs are efficient though need a few adjustments here and there in order to run without any errors or need for debugging.

notification
If you want discreet, top-grade help, order a custom paper from our experts.

If you are the original author of this essay and no longer wish to have it published on the SuperbGrade website, please click below to request its removal: