Java algorithm corporate bonus distribution

Question description

The bonuses issued by the company are based on profits. When the profit is less than or equal to 100,000 yuan, the bonus can be increased by 10%; when the profit is more than 100,000 yuan and less than 200,000 yuan, the portion less than 100,000 yuan is 10%, and the portion greater than 100,000 yuan is 10%. The commission is 7.5%; when the amount is between 200,000 and 400,000, the commission is 5% on the portion above 200,000 yuan; when the amount is between 400,000 and 600,000 yuan, the commission is 3% on the portion above 400,000 yuan; When the amount is between 600,000 and 1 million yuan, the commission is 1.5% for the portion above 600,000 yuan; when the amount is above 1 million yuan, the commission is 1% for the portion above 1 million yuan. Enter the current month's profit from the keyboard. What is the total number of bonuses to be distributed? (Keep two decimal places) The size of the profit is within double

Import entry
Import description:

Example:
210000

output

Output description:

Output example:
18000.00

HINT: Time limit: 1.0s Memory limit: 512.0MB

Problem-solving ideas

It’s just that the profits of the 5 states are different, just calculate them separately.

code

import java.util.Scanner;

public class Main {
    
    

    public static void main(String[] args) {
    
    
        Scanner scanner=new Scanner(System.in);
        double m=scanner.nextDouble();
        double n;
        if (m<=100000){
    
                 //利润低于或等于10万元时
            n=m*0.1;
        }else if (m<=200000){
    
           //利润高于10万元,低于20万元时
            n=10000+(m-100000)*0.075;
        }else if (m<=400000){
    
           //利润20万到40万之间时
            n=10000+7500+(m-200000)*0.05;
        }else if (m<=600000){
    
           //利润40万元到60万元之间时
            n=27500+(m-400000)*0.03;
        } else if (m<=1000000) {
    
        //利润60万到100万之间时
            n=27500+6000+(m-600000)*0.015;
        }else {
    
                         //利润高于100万元时
            n=27500+6000+6000+(m-1000000)*0.01;
        }
        System.out.printf("%.2f%n",n);
    }
}

Guess you like

Origin blog.csdn.net/joreng/article/details/123757219
Recommended