作业内容
(1)已知某公司员工的保底薪水为3000,某月所接工程的利润profit(整数)与利润提成的关系如下所示(计量单位:元)。计算员工的当月薪水。
工程利润 profit 提成比率
profit≤1000 没有提成
1000<profit≤2000 提成10%
2000<profit≤5000 提成15%
5000<profit≤10000 提成20%
10000<profit 提成25%
//导入 Scanner 类
import java.util.Scanner;
//主类和主方法
public class Test01 {
public static void main(String[] args) {
//初始化 Scanner 对象
Scanner sc = new Scanner(System.in);
// 基本工资
int baseSalary = 3000;
//提示用户输入利润
System.out.println("输入利润: ");
int profit = sc.nextInt();
//计算总工资并输出结果
double totalSalary = 0;
if (profit <= 1000) {
System.out.println("没有提成");
} else if (profit > 1000 && profit <= 2000) {
totalSalary = baseSalary + profit * 0.1;
System.out.println("员工的月薪水: " + String.format("%.2f", totalSalary));
} else if (profit > 2000 && profit <= 5000) {
totalSalary = baseSalary + profit * 0.15;
System.out.println("员工的月薪水: " + String.format("%.2f", totalSalary));
} else if (profit > 5000 && profit <= 10000) {
totalSalary = baseSalary + profit * 0.2;
System.out.println("员工的月薪水: " + String.format("%.2f", totalSalary));
} else {
totalSalary = baseSalary + profit * 0.25;
System.out.println("员工的月薪水: " + String.format("%.2f", totalSalary));
}
// 关闭 Scanner 对象
sc.close();
}
}