Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN JAVA 2. The Assignment Write a program that will use static methods as descri

ID: 3915285 • Letter: I

Question

IN JAVA

2. The Assignment

Write a program that will use static methods as described in the specifications below. Utilizing the if and else statements, write a program which will calculate a commission based on a two-tiered commission plan of 2% and 5% paid on amounts of $10,000 or less, or over $10,000 in sales by a sales force paid on a commission basis. Use the output specifications below.

2.1. Specifications

Prompt the user to input the total sales. That number will be input from the keyboard.

Use if and else statements to determine the appropriate commission rate to be used to calculate the commission on the sales amount entered by the user. Commission is paid at the rate of 2% on any amount of $10,000 or less in sales. Anyone selling over $10,000 is paid at the rate of 5% on the total sales amount.

Declare the necessary variables. Note that in the multiplication of the commission rate the result will potentially have a fractional part. Since the commission rates do not change, initialize them as constants.

Use the if and else statements to determine the appropriate rate for the amount of the total sales, then calculate the commission following the if/else structure.

Output the total sales amount and the commission amount and use appropriate labels for each (see below).

Use text labels on the output which make it clear what information is being displayed. Do not simply use single words like Commission or Total. Single words such as those are not descriptive enough.

Use: good variable names (should be evident what they hold), indentations of four spaces, comments within the body of the program, and label the output appropriately.

Test your program with numbers above and below the commission limits for accuracy in its calculations. Do not submit programs in which the calculations are not done correctly. Try numbers above, below, and at the commission break points.

Format the output using the printf() function. Also use a $ where appropriate.

All methods will be in the same class for this problem. The new methods will be just below the main method.

Place one blank line between each method.

2.2. Constructing the Methods

Create the following methods:

getTotalSales()

This method will display a prompt for the user to enter the total amount of the sales.

This method will return the amount of the sales that the user entered.

This method does not have parameters.

setCommRate()

This method will accept an argument which will be the sales amount entered by the user.

This method will determine the appropriate commission rate.

This method will return the commission rate.

calcCommAmount()

This method will accept the commission rate and the amount of sales entered by the user, and will calculate the amount of the commission.

This method will return the amount of commission.

displayCommResults()

This method will accept the sales amount, the commission rate, and the amount of commission.

This method will display the three items above with the output labels shown in the Output Format.

This will be a void method.

2.3. Output Format

Format the output as shown below:

You only need to calculate the commission in one place, rather than having a calculation for each type of commission. Give this aspect of the problem some thought. There are two basic ways you can do this problem as far as the location of the calculation after you have determined the commission rate. Your objective is to do the commission calculation in one place near the end of the program.

Explanation / Answer

(1)

import java.util.*;

public class commision {

public static void main(String args[]) {

double total_sale,sale_rate;

Scanner in=new Scanner(System.in);

System.out.print("Enter total sale :$");

total_sale=in.nextFloat();

if(total_sale<=10000)sale_rate=0.02;

else sale_rate=0.05;

double commission=total_sale*sale_rate;

System.out.print("Commission on $"+total_sale+" : $");

System.out.printf("%.2f",commission);

}

}

(2)

import java.util.*;

public class commision {

public static void main(String args[]) {

double total_sale,sale_rate;

total_sale=getTotalSales();

sale_rate=setSaleRate(total_sale);

double commission=calCommission(sale_rate,total_sale);

displayCommission(sale_rate,total_sale,commission);

}

static double getTotalSales() {

double sale;

Scanner in=new Scanner(System.in);

System.out.print("Enter total sale :$");

sale=in.nextFloat();

return sale;

}

static double setSaleRate(double total_sale) {

double sale_rate;

if(total_sale<=10000)sale_rate=0.02;

else sale_rate=0.05;

return sale_rate;

}

static double calCommission(double sale_rate,double total_sale) {

return sale_rate*total_sale;

}

static void displayCommission(double sale_rate,double total_sale,double commission) {

System.out.printf("The commission rate is: $%.2f " +

"The total sales amount is: $%.2f " +

"The commission earned on total sales is: $%.2f ",sale_rate,total_sale,commission);

}

}

for any query please comment.

please upvote if find helpful.

Thank you!