帮我写一个java程序···实在是不会··
题目在图片上··谢谢了classteacher{Stringname,degree,working;intage;intbasic_salary;inttotal_sal...
题目在图片上··谢谢了
class teacher
{
String name,degree,working ;
int age;
int basic_salary;
int total_salary;
int setsalary()
{
age=50;
total_salary=basic_salary+age*10;
return total_salary;
}
}
那个职称的if怎么写···不用执行··符合逻辑·在eclipse中不像是出错就行··一定要有if语句·· 展开
class teacher
{
String name,degree,working ;
int age;
int basic_salary;
int total_salary;
int setsalary()
{
age=50;
total_salary=basic_salary+age*10;
return total_salary;
}
}
那个职称的if怎么写···不用执行··符合逻辑·在eclipse中不像是出错就行··一定要有if语句·· 展开
2个回答
展开全部
public class Teacher {
private String name;//姓名
private String professional;//职称
private int workYear;//工龄
Teacher() {}
Teacher(String name, String professional, int workYear) {
this.name = name;
this.professional = professional;
this.workYear = workYear;
}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
public String getProfessional() {return professional;}
public void setProfessional(String professional) {this.professional = professional;}
public int getWorkYear() {return workYear;}
public void setWorkYear(int workYear) {this.workYear = workYear;}
public double setSalaryByProfessional(Teacher teacher) {
return teacher.getWorkYear() * 10
+ (teacher.getProfessional().equals("讲师") ? 500 : 700);
}
public void showTeacher(Teacher teacher){
System.out.println("姓名:"+teacher.getName()+"\n职称:"+teacher.getProfessional()+"\n基本工资:"+(teacher.getProfessional().equals("讲师")?500:700)+
"\n总工资:"+teacher.setSalaryByProfessional(teacher));
}
public static void main(String[] args) {
Teacher teacher=new Teacher("张三","讲师",2);
teacher.showTeacher(teacher);
teacher=new Teacher("李四","教授",10);
teacher.showTeacher(teacher);
}
}
private String name;//姓名
private String professional;//职称
private int workYear;//工龄
Teacher() {}
Teacher(String name, String professional, int workYear) {
this.name = name;
this.professional = professional;
this.workYear = workYear;
}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
public String getProfessional() {return professional;}
public void setProfessional(String professional) {this.professional = professional;}
public int getWorkYear() {return workYear;}
public void setWorkYear(int workYear) {this.workYear = workYear;}
public double setSalaryByProfessional(Teacher teacher) {
return teacher.getWorkYear() * 10
+ (teacher.getProfessional().equals("讲师") ? 500 : 700);
}
public void showTeacher(Teacher teacher){
System.out.println("姓名:"+teacher.getName()+"\n职称:"+teacher.getProfessional()+"\n基本工资:"+(teacher.getProfessional().equals("讲师")?500:700)+
"\n总工资:"+teacher.setSalaryByProfessional(teacher));
}
public static void main(String[] args) {
Teacher teacher=new Teacher("张三","讲师",2);
teacher.showTeacher(teacher);
teacher=new Teacher("李四","教授",10);
teacher.showTeacher(teacher);
}
}
追问
这个问题··我提了两次····麻烦你复制过去把我的另外一个也回了吧····楼下的更加符合老师要求,当让不能让你白呢忙呢·很感谢你,另一个问题你复制过去我采纳一下
展开全部
public class Teacher {
private String name; // 姓名
private String grade; // 职称等级
private int workYear; // 工龄
private int basicSalary; // 基本工资
// 计算工资
public int calculateSalary() {
return workYear * 10 + basicSalary;
}
// 根据职称设置工资
public void setGrade(String grade) {
this.grade = grade;
if ("讲师".equals(this.grade)) {
basicSalary = 500;
} else if ("教授".equals(this.grade)) {
basicSalary = 700;
}
}
}
这个应该可以吧。
private String name; // 姓名
private String grade; // 职称等级
private int workYear; // 工龄
private int basicSalary; // 基本工资
// 计算工资
public int calculateSalary() {
return workYear * 10 + basicSalary;
}
// 根据职称设置工资
public void setGrade(String grade) {
this.grade = grade;
if ("讲师".equals(this.grade)) {
basicSalary = 500;
} else if ("教授".equals(this.grade)) {
basicSalary = 700;
}
}
}
这个应该可以吧。
追问
这个很满意··上面看不太懂···我不太专业,才学没几天·谢谢呢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询