m0_63853120 2023-04-15 20:47 采纳率: 66.7%
浏览 18
已结题

关于#java#的问题,请各位专家解答!

package emppackage;

class Mydate{
    private int year;
    private int month;
    private int day;
    public  Mydate(int year,int month,int date) {
        this.year=year;
        this.month=month;
        this.day=date;
    }
    public String toDateString()
    {
        return year+"年"+month+"月"+day+"日";
    }
}

abstract class employee1{
private String name;    
private String num;
private Mydate birthday;
abstract public int earnings();
public employee1(String name,String num,Mydate birthday)
{this.name=name;
 this.num=num;
 this.birthday=birthday;
    
}
public String toString()
{
    return "姓名:"+name+","+"工号:"+num+","+"生日:"+birthday.toDateString();
}

}


class SalariedEmployee extends employee1{
    private int monthlysalary;
    public SalariedEmployee(String name,String num,Mydate birthday,int monthlysalary){
        super(name,num,birthday);
        this.monthlysalary=monthlysalary;
    }
    public int earnings() {
        return monthlysalary;
    }

    public String toString(){                    
        return "月工:"+super.toString();      
    }    



 class HourlyEmployee extends employee1{
    private int hour;
    private int wage;
    public HourlyEmployee(String name,String num, Mydate birthday,int hour,int wage){
        super(name,num,birthday);
        this.hour=hour;
        this.wage=wage;
    }
    public int earnings(){
        return hour*wage;
    }

    public String toString(){
        return "小时工"+super.toString();
    
    }
    
}
 
 
public class Employee {
    public static void main(String args[]){
    employee1 c1[]=new employee1 [4];
    Mydate a=new Mydate(2000,11,120);
    c1[0]=new SalariedEmployee("张三","202226",a,3000);
    System.out.println("c1.toString()");    
}
}

    

怎么修改gets()输出信息

  • 写回答

2条回答 默认 最新

  • Huazie 全栈领域优质创作者 2023-04-15 20:52
    关注

    刚才怎么删了? 我给你改了,参考如下:
    gets() 没必要调用,如果你想用,也可以 super.gets()

    /**
     * @author huazie
     * @version 2.0.0
     * @since 2.0.0
     */
    class Mydate {
        private int year;
        private int month;
        private int day;
    
        public Mydate(int year, int month, int date) {
            this.year = year;
            this.month = month;
            this.day = date;
        }
    
        public String toDateString() {
            return year + "年" + month + "月" + day + "日";
        }
    }
    
    abstract class employee1 {
        private String name;
        private String num;
        private Mydate birthday;
    
        abstract public int earnings();
    
        public employee1(String name, String num, Mydate birthday) {
            this.name = name;
            this.num = num;
            this.birthday = birthday;
    
        }
    
        public String toString() {
            return "姓名:" + name + "," + "工号:" + num + "," + "生日:" + birthday.toDateString();
        }
    
        public String gets() {
            return "姓名:" + name + "," + "工号:" + num + "," + "生日:" + birthday.toDateString();
        }
    
    }
    
    class SalariedEmployee extends employee1 {
        private int monthlysalary;
    
        public SalariedEmployee(String name, String num, Mydate birthday, int monthlysalary) {
            super(name, num, birthday);
            this.monthlysalary = monthlysalary;
        }
    
        @Override
        public int earnings() {
            return monthlysalary;
        }
    
        public String toString() {
            return "月工:" + super.toString();
        }
    }
    
    class HourlyEmployee extends employee1 {
        private int hour;
        private int wage;
    
        public HourlyEmployee(String name, String num, Mydate birthday, int hour, int wage) {
            super(name, num, birthday);
            this.hour = hour;
            this.wage = wage;
        }
    
        @Override
        public int earnings() {
            return hour * wage;
        }
    
        public String toString() {
            return "小时工" + super.toString();
        }
    
    }
    
    public class Employee {
        public static void main(String args[]) {
            employee1 c1[] = new employee1[4];
            Mydate a = new Mydate(2000, 11, 120);
            c1[0] = new SalariedEmployee("张三", "202226", a ,3000);
            System.out.println(c1[0]);
        }
    }
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月23日
  • 已采纳回答 4月15日
  • 修改了问题 4月15日
  • 创建了问题 4月15日

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么