您当前的位置:首页 > 互联网教程

java中的实现类是什么意思

发布时间:2025-05-21 10:26:26    发布人:远客网络

java中的实现类是什么意思

一、java中的实现类是什么意思

1、实现类就是实现接口中约定的内容。

2、意思是说,接口中定义规范,实现类来确定规范如何运行的。比如接口定义一个Person接口,定义了一个eat方法,这个吃的方法是空的。

3、那需要一个实现类比如ZhangSan类实现了Person接口,就必须要给定eat方法的具体实现,说明张三是如何吃的。

二、Java编写开一个类实现以下功能:

importjava.text.ParseException;

importjava.text.SimpleDateFormat;

publicstaticvoidmain(String[]args)throwsParseException{

SimpleDateFormatformat=newSimpleDateFormat("yyyy-MM-ddHH:mm");

Datebegin=format.parse("2014-11-0309:00");

Dateend=format.parse("2015-03-0918:00");

Date[]festival={format.parse("2015-01-0100:00"),

format.parse("2015-01-0200:00"),

format.parse("2015-01-0300:00"),

format.parse("2015-01-0400:00")};

List<Date[]>month=getDateMonths(begin,end);

List<List<Date>>workDay=getWorkDate(month,festival);

publicstaticvoidwork(List<List<Date>>dates){

Calendarcalendar=Calendar.getInstance();

for(List<Date>date:dates){

for(inti=0;i<date.size();i++){

calendar.setTime(date.get(i));

inttempHour=calendar.get(Calendar.HOUR_OF_DAY);

if((i+1)!=date.size()){//非结束天以开始时间为准

calendar.set(calendar.get(Calendar.YEAR),

calendar.get(Calendar.DAY_OF_MONTH),

if(date.get(i).before(calendar.getTime())){

//开始时间在当天凌晨10分前,算整天,可按需调整

}else{//最后一天以结束时间为准

calendar.set(calendar.get(Calendar.YEAR),

calendar.get(Calendar.DAY_OF_MONTH),

if(date.get(i).before(calendar.getTime())&&tempHour!=0){

//开始时间在当天晚上50分后,算整天,可按需调整

System.out.println(calendar.get(Calendar.YEAR)+"年"+(calendar.get(Calendar.MONTH)+1)+

"月加班"+dayNum+"天"+hourNum+"小时");

publicstaticList<List<Date>>getWorkDate(List<Date[]>dates,Date[]festival){

ArrayList<List<Date>>result=newArrayList<List<Date>>();

CalendarcBegin=Calendar.getInstance();

CalendarcEnd=Calendar.getInstance();

SimpleDateFormatformat=newSimpleDateFormat("yyyy-MM-dd");

for(inti=0;i<dates.size();i++){

cBegin.setTime(dates.get(i)[0]);

cEnd.setTime(dates.get(i)[1]);

intday=cEnd.get(Calendar.DAY_OF_MONTH)-cBegin.get(Calendar.DAY_OF_MONTH);

List<Date>date=newArrayList<Date>();

cBegin.add(Calendar.DAY_OF_MONTH,1);

cBegin.set(Calendar.HOUR_OF_DAY,0);//非开始天,开始时间为0点

//结束天,开始时间为24-结束小时数

cBegin.set(Calendar.HOUR_OF_DAY,(23-cEnd.get(Calendar.HOUR_OF_DAY)));

Stringbegin=format.format(cBegin.getTime());

for(intf=0;f<festival.length;f++){

if(begin.equals(format.format(festival[f]))){

if(cBegin.get(Calendar.DAY_OF_WEEK)==1||cBegin.get(Calendar.DAY_OF_WEEK)==7){

*根据开始结束时间返回时间段内每月开始结束时间

*@return{date1:[monthBegin,monthEnd],date2:[monthBegin,monthEnd]}

publicstaticList<Date[]>getDateMonths(Datebegin,Dateend){

List<Date[]>months=newArrayList<Date[]>();

System.out.println("Baddateofbeginorend...");

CalendarcBegin=Calendar.getInstance();

CalendarcEnd=Calendar.getInstance();

intbeginYear=cBegin.get(Calendar.YEAR);

intendYear=cEnd.get(Calendar.YEAR);

intbeginMonth=cBegin.get(Calendar.MONTH);

intendMonth=cEnd.get(Calendar.MONTH);

intendDay=cEnd.get(Calendar.DAY_OF_MONTH);

intendHour=cEnd.get(Calendar.HOUR_OF_DAY);

intendMinu=cEnd.get(Calendar.MINUTE);

monthNum+=endMonth-beginMonth;

}elseif((1+beginYear)==endYear){

monthNum+=12-beginMonth+endMonth;

monthNum+=12-beginMonth+endMonth+(endYear-beginYear-1)*12;

for(inti=0;i<monthNum;i++){

cBegin.set(cBegin.get(Calendar.YEAR),cBegin.get(Calendar.MONTH)

cEnd.set(cBegin.get(Calendar.YEAR),cBegin.get(Calendar.MONTH)

,cBegin.getActualMaximum(Calendar.DATE)

cEnd.set(cBegin.get(Calendar.YEAR),cBegin.get(Calendar.MONTH)

Date[]date={cBegin.getTime(),cEnd.getTime()};

*/

分为:开始结束时间按月统计、去除无效天、统计时长三个函数,应该能明白吧

分为:开始结束时间按月统计、去除无效天、统计时长三个函数,应该能明白吧

细节上多久算一天,还有节假日的可以自行调节,不再累述

三、java工厂类怎么实现

1、普通工厂模式,就是建立一个工厂类,对实现了同一接口的一些类进行实例的创建

2、多个工厂方法模式,是对普通工厂方法模式的改进,在普通工厂方法模式中,如果传递的字符串出错,则不能正确创建对象,而多个工厂方法模式是提供多个工厂方法,分别创建对象。

3、静态工厂方法模式,将上面的多个工厂方法模式里的方法置为静态的,不需要创建实例,直接调用即可。

具体代码请参考:java设计模式第三大节

如果对您有帮助,请及时采纳谢谢