首页 > 其他分享 >抽象类的实例应用

抽象类的实例应用

时间:2022-10-23 19:11:17浏览次数:67  
标签:return name int number birthday 实例 应用 抽象类 public

1.员工

package bigguy;

/**
* @author liu$
* @version 1.0
* @description: TODO
* @date $ $
*/
public abstract class Employee {
private String name ;
private int number ;
private MyDate birthday ;

public Employee(String name, int number, MyDate birthday) {
this.name = name;
this.number = number;
this.birthday = birthday;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getNumber() {
return number;
}

public void setNumber(int number) {
this.number = number;
}

public MyDate getBirthday() {
return birthday;
}

public void setBirthday(MyDate birthday) {
this.birthday = birthday;
}

public abstract double earnings( ) ;

@Override
public String toString() {
return "name='" + name + '\'' +
", number=" + number +
", birthday=" + birthday.toDateString() +
'}';
}


}
2.生日
package bigguy;

/**
* @author liu$
* @version 1.0
* @description: TODO
* @date $ $
*/
public class MyDate {
private int year ;
private int month ;
private int day ;

public MyDate(int year, int month, int day) {
this.year = year;
this.month = month;
this.day = day;
}

public int getYear() {
return year;
}

public void setYear(int year) {
this.year = year;
}

public int getMonth() {
return month;
}

public void setMonth(int month) {
this.month = month;
}

public int getDay() {
return day;
}

public void setDay(int day) {
this.day = day;
}

public String toDateString() {
return "MyDate{" +
"year=" + year +
", month=" + month +
", day=" + day +
'}';
}
}
3.普通月薪员工
package bigguy;

/**
* @author liu$
* @version 1.0
* @description: TODO
* @date $ $
*/
public class SalariedEmployee extends Employee {
private double mothlysalary ;
public SalariedEmployee(String name, int number, MyDate birthday) {
super(name, number, birthday);
}
public SalariedEmployee(String name, int number, MyDate birthday,double mothlysalary) {

super(name, number, birthday);
this.mothlysalary = mothlysalary;
}

public double getMothlysalary() {
return mothlysalary;
}

public double earnings() {

return mothlysalary ;
}

public String toString() {
return "SalariedEmployee{" +super.toString() +"]" ;
}
}
4.小时工
package bigguy;

/**
* @author liu$
* @version 1.0
* @description: TODO
* @date $ $
*/
public class HourlyEmployee extends Employee {
private int wage;//每小时工资
private int hour;//一个月工作了多少小时

public HourlyEmployee(String name , int number , MyDate birthday ) {
super( name , number , birthday ) ;
}

public HourlyEmployee(String name , int number , MyDate birthday ,int wage,int hour) {
super( name , number , birthday ) ;
this.wage = wage ;
this.hour = hour ;
}

public int getWage() {
return wage;
}

public void setWage(int wage) {
this.wage = wage;
}

public int getHour() {
return hour;
}

public void setHour(int hour) {
this.hour = hour;
}

@Override
public double earnings() {
return wage * hour;
}
public String toString() {
return "HourlyEmployee{" + super.toString() + "]";
}
}
5.总薪水(生日+100)
package bigguy;

import java.util.Scanner;

/**
* @author liu$
* @version 1.0
* @description: TODO
* @date $ $
*/
public class PayrollSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in) ;
System.out.println("请输入当月的月份:");
int month = scanner.nextInt() ;
Employee[] emps = new Employee[2] ;
emps[0] = new SalariedEmployee("大嘴盈",1001,new MyDate(2003,9,28),5000) ;
emps[1] = new HourlyEmployee("柳",1002,new MyDate(2003,8,10),240,60) ;

for (int i = 0; i < emps.length; i++) {
System.out.println(emps[i]);
double salary = emps[i].earnings() ;
System.out.println("月工资为:"+salary);

if (month==emps[i].getBirthday().getMonth()){
System.out.println("生日快乐,给你加100块");
}
}
}
}

标签:return,name,int,number,birthday,实例,应用,抽象类,public
From: https://www.cnblogs.com/liujy2233/p/16819181.html

相关文章

  • 实验7:基于REST API的SDN北向应用实践
    实验7:基于RESTAPI的SDN北向应用实践一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。二、实验......
  • 信息化应用场景,华为云CDN能为企业做什么?​
    信息化应用场景,华为云CDN能为企业做什么?​随着信息化技术在各行业的广泛应用,人们对于数据传输的要求也越来越高。传统的互联网已经不能满足目前需求,需要一种新型高效可靠的......
  • 实验2 C语言控制语句应用编程
     任务一:#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){nu......
  • classmethod的应用
    classStuent(object):stu_num=0__stu_num=0name=333def__init__(self,name):self.name=name#self.stu_num+=1#这就相当于......
  • Spring —— bean实例化
    bean实例化bean本质上就是对象,创建bean使用构造方法完成(反射)    构造方法(常用)      静态工厂*      实例工厂*      FactoryBean(实用)......
  • 【前端】web网站应用微信扫码登陆功能实现
    视频参考......
  • Java 实例 - 数组差集
    https://www.runoob.com/java/arrays-removeall.htmlhttps://blog.csdn.net/weixin_43552143/article/details/124878630......
  • 抽象类的应用
    packageTemplate;/***@authorliu$*@version1.0*@description:TODO*@date$$*/publicclassTemplateTest{publicstaticvoidmain(String[]args){......
  • 结构体的应用
    在C语言中,我们不免会遇到一些难以描述的对象,像一些动物呀,你在描述它的时候,需要将它的外形,体态,颜色,种类都应该讲出来。这时候我们引入结构体---struct(本义:结构,它是一个关键......
  • 移动应用软件常见的操作系统
    随着互联网技术的进步和软件形态的不断发展,移动应用软件(或称为移动终端软件)已经成为普通大众广泛使用的新型软件。因此,移动应用软件质量越来越受重视。移动应用软件与传统......