中央論壇 - CENTER BBS

標題: IVE Exercise 3.1 Sample [打印本頁]

作者: f66666602    時間: 2007-7-27 21:13
標題: IVE Exercise 3.1 Sample
// Exercise 3.1

import javax.swing.*;

public class sale_amount {
  
  static String input_goal_st;
  static int input_goal_int;
  static double base_salary = 5000;
  static double rate_1 = 8;
  static double rate_2 = 10;
  static double rate_3 = 12;
  static double limit_high_1 = 5000;
  static double limit_high_2 = 10000;
  static double limit_high_3 = 10000.01;
  static double limit_low_1 = 0.01;
  static double limit_low_2 = 5000;
  static double limit_low_3 = 10000;
  static String range_1 = "$0.01 - $5,000";
  static String range_2 = "$5,000.01 - $10,000";
  static String range_3 = "$10,000.01 and above";
  static double total_month = 12;
  static double mini_amount;
  static double sale_amount;
  static double sale_amount_final;
  static String x;
  static double y;
  static double z;
  static double w;
  static int i;
  
  public static void main(String[] args) {
   
    input_goal_st = JOptionPane.showInputDialog(null, "Input your targe commission of this year", "Calculation of commission",
                                                JOptionPane.QUESTION_MESSAGE);
   
    input_goal_int = Integer.parseInt(input_goal_st);
   
    for(i = 1; i <= 3; i++) {
      
      switch(i) {
        case 1 : x = range_1; y = limit_high_1; z = rate_1; w = limit_low_1;
        break;
        case 2 : x = range_2; y = limit_high_2; z = rate_2; w = limit_low_2;
        break;
        case 3 : x = range_3; y = limit_high_3; z = rate_3; w = limit_low_3;
        break;
      }
      
      mini_amount = (w * total_month);
      sale_amount = (base_salary) + (y * (z / 100) * total_month);
      
      if (sale_amount >= input_goal_int) {
        sale_amount_final = (input_goal_int - base_salary) * (100 / z);
        if ( sale_amount_final >= mini_amount) {
        System.out.println("The sale amount to meet your goal is " + sale_amount_final + "\nCommission rate is " + z + "\nSales amount range is " + x);
        JOptionPane.showMessageDialog(null, "The sale amount to meet your goal is " + sale_amount_final + "\nCommission rate is " + z + "\nSales amount range is " + x, "The information of the calculation", JOptionPane.INFORMATION_MESSAGE);
        } else {
          continue;
        }
      } else if(i == 3) {
        sale_amount_final = (input_goal_int - base_salary) * (100 / rate_3);
        if ( sale_amount_final >= mini_amount) {
          System.out.println("The sale amount to meet your goal is " + sale_amount_final + "\nCommission rate is " + z + "\nSales amount range is " + x);
                JOptionPane.showMessageDialog(null, "The sale amount to meet your goal is " + sale_amount_final + "\nCommission rate is " + z + "\nSales amount range is " + x, "The information of the calculation", JOptionPane.INFORMATION_MESSAGE);
        } else {
          continue;
        }     
      } else {
        continue;
      }
    }
  }
}




歡迎光臨 中央論壇 - CENTER BBS (https://www.centerbbs.com/) Powered by Discuz! X3