一道很基础的题但是由于放假我之间给整不会了尴尬了,具体的要求在图片上,希望能手帮帮忙谢谢!
2条回答 默认 最新
- 卑以自牧w 2021-09-11 22:20关注
#员工类
```java class Csdn { private String name; private int age; private String position; private int salary; public Csdn(){ } public Csdn(String name, int age, String position, int salary) { this.name = name; this.setAge(age); this.setPosition(position); this.setSalary(salary); } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { if (age>=18){ this.age=age; }else{ this.age=18; System.out.println("年龄信息输入有误!默认修改为18!"); } } public String getPosition() { return position; } public void setPosition(String position) { if (position=="售后服务"||position=="销售员"){ this.position=position; }else{ this.position="售后服务"; System.out.println("职位信息输入有误!默认修改为售后服务!"); } } public int getSalary() { return salary; } public void setSalary(int salary) { if (this.getAge()>=18&this.getAge()<=20){ this.salary=1000; }else if (this.getAge()>=21&this.getAge()<=25){ this.salary=1500; }else if (this.getAge()>=26&this.getAge()<=30){ this.salary=2000; }else if (this.getAge()>=31&this.getAge()<=40){ this.salary=3000; }else if (this.getAge()>=41&this.getAge()<=50){ this.salary=3500; }else if (this.getAge()>50){ this.salary=4000; } } public void message(){ System.out.println("姓名:"+this.getName()+"\n"+"年龄:"+this.getAge()+"\n"+ "职位:"+this.getPosition()+"\n"+"薪水:"+this.getSalary()); } } #测试类 ```java public class Employee { public static void main(String[] args) { Csdn csdn = new Csdn("张三",20,"总经理",1000); csdn.message(); Csdn csdn1 = new Csdn("李四", 26, "销售员", 2500); csdn1.message(); } } #具体你自己运行吧 应该是没有问题的
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 2024-五一综合模拟赛
- ¥15 下图接收小电路,谁知道原理
- ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
- ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
- ¥15 手机接入宽带网线,如何释放宽带全部速度
- ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
- ¥15 ETLCloud 处理json多层级问题
- ¥15 matlab中使用gurobi时报错
- ¥15 这个主板怎么能扩出一两个sata口
- ¥15 不是,这到底错哪儿了😭