求Java代码 编写一个类 完成以下任务
编写一个类Teacher,描述教师的员工号(int)、姓名(String)、岗位工资(double)、绩效工资(double)、课时数量(double)和课时系数(dou...
编写一个类Teacher, 描述教师的员工号(int)、姓名(String)、岗位工资(double)、绩效工资(double)、课时数量(double)和课时系数(double),所有教师的课时系数相同。
编写一个带参数的构造方法给员工号、姓名、岗位工资、绩效工资、课时数量进行初始化;、
编写一个方法计算并返回教师的总工资(总工资=岗位工资+绩效工资);
编写一个方法计算并返回教师的当量课时(当量课时=课时数量*课时系数);
编写一个测试类进行测试,创建两个教师对象,输出两位教师的姓名+总工资;输出课时系数为1.2时,两位教师的当量课时;将课时系数改为1.1时,输出两位教师的当量课时。 展开
编写一个带参数的构造方法给员工号、姓名、岗位工资、绩效工资、课时数量进行初始化;、
编写一个方法计算并返回教师的总工资(总工资=岗位工资+绩效工资);
编写一个方法计算并返回教师的当量课时(当量课时=课时数量*课时系数);
编写一个测试类进行测试,创建两个教师对象,输出两位教师的姓名+总工资;输出课时系数为1.2时,两位教师的当量课时;将课时系数改为1.1时,输出两位教师的当量课时。 展开
2个回答
展开全部
帮你写好啦,采纳吧。
public class Teacher {
// 员工号
private int id;
// 姓名
private String name;
// 工资
private double salary;
// 绩效工资
private double bonus;
// 课时数量
private double lessonNum;
// 课时系数
private static double lessonRate = 1;
public Teacher(int id, String name, double salary, double bonus, double lessonNum) {
this.id = id;
this.name = name;
this.salary = salary;
this.bonus = bonus;
this.lessonNum = lessonNum;
}
// 总工资
public double sumSalary() {
return salary + bonus;
}
// 当量课时
public double curLessonNum() {
return lessonNum * lessonRate;
}
public static void setLessonRate(double lessonRate) {
Teacher.lessonRate = lessonRate;
}
// 测试
public static void main(String[] args) {
// 创建两个教师对象,输出两位教师的姓名+总工资
Teacher t1 = new Teacher(1, "zhangSan", 5000, 2000, 20);
Teacher t2 = new Teacher(2, "wangWu", 6000, 4000, 30);
System.out.println("姓名" + t1.name + "总工资" + t1.sumSalary());
System.out.println("姓名" + t2.name + "总工资" + t2.sumSalary());
// 输出课时系数为1.2时,两位教师的当量课时
Teacher.setLessonRate(1.2);
System.out.println(t1.name + "当量课时:" + t1.curLessonNum());
System.out.println(t2.name + "当量课时:" + t1.curLessonNum());
// 输出课时系数为1.1时,两位教师的当量课时
Teacher.setLessonRate(1.1);
System.out.println(t1.name + "当量课时:" + t1.curLessonNum());
System.out.println(t2.name + "当量课时:" + t1.curLessonNum());
}
}
运行结果:
展开全部
//构造方法的类
package com.sysway.contract.action;
public class Teacher {
private int num;
private String name;
private double gwmoney;
private double jxmoney;
private double sum;
private double coefficient;
public Teacher(int num,String name,double gwmoney,double jxmoney,double sum){
this.num = num;
this.name = name;
this.gwmoney = gwmoney;
this.jxmoney = jxmoney;
this.sum = sum;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getGwmoney() {
return gwmoney;
}
public void setGwmoney(double gwmoney) {
this.gwmoney = gwmoney;
}
public double getJxmoney() {
return jxmoney;
}
public void setJxmoney(double jxmoney) {
this.jxmoney = jxmoney;
}
public double getSum() {
return sum;
}
public void setSum(double sum) {
this.sum = sum;
}
public double getCoefficient() {
return coefficient;
}
public void setCoefficient(double coefficient) {
this.coefficient = coefficient;
}
//返回总工资
public double getAllMoney(){
double allMoney = 0;
allMoney = this.gwmoney+this.jxmoney;
return allMoney;
}
//返回课时当量
public double getEquivalent(){
double equivalent = 0;
equivalent = this.getSum()*this.coefficient;
return equivalent;
}
}
//测试类
package com.sysway.contract.action;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Teacher tech1 = new Teacher(1,"张三",2000,1500,40);
Teacher tech2 = new Teacher(2,"李四",3000,2000,50);
System.out.println(tech1.getName()+":"+tech1.getAllMoney());
System.out.println(tech2.getName()+":"+tech2.getAllMoney());
tech1.setCoefficient(1.2);
tech2.setCoefficient(1.2);
System.out.println(tech1.getName()+"课时当量:"+tech1.getEquivalent());
System.out.println(tech2.getName()+"课时当量:"+tech2.getEquivalent());
tech1.setCoefficient(1.1);
tech2.setCoefficient(1.1);
System.out.println(tech1.getName()+"课时当量:"+tech1.getEquivalent());
System.out.println(tech2.getName()+"课时当量:"+tech2.getEquivalent());
}
}
有问题,共同讨论,共同进步,希望采纳。
package com.sysway.contract.action;
public class Teacher {
private int num;
private String name;
private double gwmoney;
private double jxmoney;
private double sum;
private double coefficient;
public Teacher(int num,String name,double gwmoney,double jxmoney,double sum){
this.num = num;
this.name = name;
this.gwmoney = gwmoney;
this.jxmoney = jxmoney;
this.sum = sum;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getGwmoney() {
return gwmoney;
}
public void setGwmoney(double gwmoney) {
this.gwmoney = gwmoney;
}
public double getJxmoney() {
return jxmoney;
}
public void setJxmoney(double jxmoney) {
this.jxmoney = jxmoney;
}
public double getSum() {
return sum;
}
public void setSum(double sum) {
this.sum = sum;
}
public double getCoefficient() {
return coefficient;
}
public void setCoefficient(double coefficient) {
this.coefficient = coefficient;
}
//返回总工资
public double getAllMoney(){
double allMoney = 0;
allMoney = this.gwmoney+this.jxmoney;
return allMoney;
}
//返回课时当量
public double getEquivalent(){
double equivalent = 0;
equivalent = this.getSum()*this.coefficient;
return equivalent;
}
}
//测试类
package com.sysway.contract.action;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Teacher tech1 = new Teacher(1,"张三",2000,1500,40);
Teacher tech2 = new Teacher(2,"李四",3000,2000,50);
System.out.println(tech1.getName()+":"+tech1.getAllMoney());
System.out.println(tech2.getName()+":"+tech2.getAllMoney());
tech1.setCoefficient(1.2);
tech2.setCoefficient(1.2);
System.out.println(tech1.getName()+"课时当量:"+tech1.getEquivalent());
System.out.println(tech2.getName()+"课时当量:"+tech2.getEquivalent());
tech1.setCoefficient(1.1);
tech2.setCoefficient(1.1);
System.out.println(tech1.getName()+"课时当量:"+tech1.getEquivalent());
System.out.println(tech2.getName()+"课时当量:"+tech2.getEquivalent());
}
}
有问题,共同讨论,共同进步,希望采纳。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询