Friday, 19 August 2016

Chapter 6 Exercise 11, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY.

6.11 (Financial application: compute commissions) Write a method that computes the commission, using the scheme in Programming Exercise 5.39. The header of the method is as follows: public static double computeCommission(double salesAmount) Write a test program that displays the following table:


Sales Amount Commission
10000 900.0
15000 1500.0
...
95000 11100.0
100000 11700.0

public class ProgrammingExercise6_11 {
 
 public static void main(String[] args) {
  
  System.out.printf("%-15s%-15s\n","Sales Amount", "Commission");
 
  for (int i = 10000; i <= 100000; i += 5000) {
 
   System.out.printf("%-15d%-15.2f\n", i, computeCommission(i));
 
  }
 
 }
 
 public static double computeCommission(double salesAmount) {
  double commission;
  if (salesAmount > 10000) {
   commission = (5000 * 0.08) + (5000 * 0.1) + (salesAmount - 10000)
     * 0.12;
  } else if (salesAmount > 5000) {
   commission = 5000 * 0.08 + (salesAmount - 5000) * 0.1;
  } else {
   commission = salesAmount * 0.08;
  }
 
  return commission;
 
 }
 
}

No comments :

Post a Comment