1.(15)某公司销售员的工资包括基本工资和销售提成。销售提成根据下面表1计算: 表 1 销售额 提成 30.00 元到 299.99元 销售额的5% 300.00元到999.99元 销售额的10% 班 大于等于 1000.00元 销售额的 15% 级 编写销售员类,使用该类的对象可计算销售员的实际工资。要求编写构造函数,使用构造函数 参数初始化对象属性的值。 违 2.(10分)编写应用程序,输入雇员编号,基本工资和销售额,使用上面编写的销售员类,使 用有参数的构造函数创建销售员对象,调用该对象的方法计算该销售员的实际工资,并输出工 试 资单(雇员编号,基本工资、销售额和实际工资)要求使用NumberFormat类(样本数据如图2 卷 所示)。 输入 轴入 输入 作 线 零 100001 请销入销售员编号 请输入基本工资 23698 请输入销售额 8000 处 确定 取消 确定 取消 结果 销售员编号:100001基本工资:¥8,000.00销售额:¥23,698.00工资:¥11,554.70使用构造方法,JAVA
时间: 2024-03-21 12:38:35 浏览: 25
销售员类的代码如下:
```java
import java.text.NumberFormat;
public class Salesman {
private int employeeID; // 雇员编号
private double baseSalary; // 基本工资
private double salesAmount; // 销售额
public Salesman(int employeeID, double baseSalary, double salesAmount) {
this.employeeID = employeeID;
this.baseSalary = baseSalary;
this.salesAmount = salesAmount;
}
public double calculateSalary() {
double commissionRate;
if (salesAmount >= 1000) {
commissionRate = 0.15;
} else if (salesAmount >= 300) {
commissionRate = 0.1;
} else {
commissionRate = 0.05;
}
return baseSalary + salesAmount * commissionRate;
}
public void printSalary() {
double salary = calculateSalary();
NumberFormat formatter = NumberFormat.getCurrencyInstance();
System.out.println("销售员编号:" + employeeID);
System.out.println("基本工资:" + formatter.format(baseSalary));
System.out.println("销售额:" + formatter.format(salesAmount));
System.out.println("工资:" + formatter.format(salary));
}
}
```
应用程序的代码如下:
```java
import java.text.NumberFormat;
import java.util.Scanner;
public class SalesmanApp {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入销售员编号:");
int employeeID = scanner.nextInt();
System.out.print("请输入基本工资:");
double baseSalary = scanner.nextDouble();
System.out.print("请输入销售额:");
double salesAmount = scanner.nextDouble();
Salesman salesman = new Salesman(employeeID, baseSalary, salesAmount);
salesman.printSalary();
}
}
```
输入样例:
```
请输入销售员编号:100001
请输入基本工资:8000
请输入销售额:23698
```
输出样例:
```
销售员编号:100001
基本工资:¥8,000.00
销售额:¥23,698.00
工资:¥11,554.70
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)