In: Computer Science
CIT 149 JAVA 1 program question?
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 3% and 7% paid on amounts of $15,000 or less, or over $15,000 in monthly sales by a sales force paid on a commission basis. Use the output specifications below.
? Specifications
? 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.
? Constructing the Methods
Create the following methods in the CommCalc class (separate file):
? The Commission class (file) will contain the
main method, and it is the main method from which
each of the methods below will be called.
The main method will control the logic within the
program.
inputTotalSales()
setCommRate()
calcCommAmount()
displayCommResults()
? Output Format
Format the output as shown below (the 9s just represent possible numbers):
***** Commission Calculation ***** The commission rate is: 9.99 The total monthly sales amount is: $99999.00 The commission earned on total monthly sales is: $999.00
? Meaningful description of the purpose of the
program.
I will be looking for good descriptions of what your program does.
An example of a description might look like the following (not for
this program of course):
Description: This program accepts input from the
keyboard as an amount of a purchase as a double, and calculates a
discount based on a customer type using a four-tier percentage
scale of 2%, 4%, 6%, and 8%. The output is the amount of the
discount rounded to two decimal places and the total purchase less
the discount, also rounded to two decimal places.
thanks for the question, here are the two classes -
Comments included and variable names are descriptiove for you to follow the code. let me know for any questions or problem.
================================================================
import java.util.Scanner;
public class CompCalc {
public CompCalc() {
}
public double inputTotalSales()
{
// scanner object to
take user input
Scanner scanner =
new Scanner(System.in);
System.out.print("Enter the total amount
of monthly sales: ");
double
sales = scanner.nextDouble();
return
sales;
}
public double
setCommRate(double totalSales){
// if the sales is below
or equal to 15000 set percentage as 3%
if(totalSales<=15000)return
3;
else
return 5; // else its 7% above 15000
}
public double
calcCommAmount(double rate,
double totalSales){
// calculate commission
amount and return the value
return
rate*totalSales/100;
}
public void
displayCommResults(double totalSales,
double rate, double
commissionAmount){
System.out.println("********* Commission
Calculation ************");
System.out.printf("The comission rate is
%.2f\n",rate);
System.out.printf("The total monthly sales
amount is
$%.2f\n",totalSales);
System.out.printf("The commission earned
on total monthly sales is:
$%.2f\n",commissionAmount);
}
}
================================================================
public class Commission { public static void main(String[] args) { // create an object of CompCalc c CompCalc calculator = new CompCalc(); // take total sales amount from user double totalSales = calculator.inputTotalSales(); // find the rate for the sales amount double rate = calculator.setCommRate(totalSales); // calculate the commission double commissionAmount = calculator.calcCommAmount(rate,totalSales); // display all the results calculator.displayCommResults(totalSales,rate,commissionAmount); } }
================================================================