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日

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题