欢迎来到天天文库
浏览记录
ID:42555756
大小:16.43 KB
页数:6页
时间:2019-09-17
《2019java程序设计(第二版)课后习题答案》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、java程序设计(第二版)课后习题答案 //习题import*;classMyDate{privateintyear;privateintmonth;privateintday; publicMyDate(inty,intm,intd){//构造函数,构造方法 year=y; month=m; day=d; }//endpublicMyDate(inty,intm,intd)publicintgetYear{//返回年 returnyear;}//endgetYear publicintget
2、Month{//返回月 returnmonth;}//endgetMonth publicintgetDay{//返回日 returnday;}//endgetDay}//endclassMyDateclassEmployee{ privateStringname; privatedoublesalary; privateMyDatehireDay; publicEmployee(Stringn,doubles,MyDated){ name=n; salary=s; hireDay=d;
3、 }//endpublicEmployee(Stringn,doubles,MyDated) publicvoidprint{ (名字:工资:雇佣年份: }//endprint publicvoidraiseSalary(doublebyPercent){ salary*=1+byPercent/100; }//end publicinthireYear{ return; } }//endclassEmployeepublicclassMyTestClass{ publicsta
4、ticvoidmain(Stringargs){ Employeestaff=newEmployee[3]; staff[0]=newEmployee( staff[1]=newEmployee( staff[2]=newEmployee(ester intintegerValue; ( for(integerValue=0;integerValue<=2;integerValue++){ staff[integerValue].raiseSalary(5); }//endfor(
5、) for(integerValue=0;integerValue<=2;integerValue++){ staff[integerValue].print(); }//endfor()}//endmain() }//endclassMyTestClass//习题import*; publicclassDataType{ publicstaticvoidmain(Stringargs){ booleanflag; charyesChar; bytefinByte; intintValue
6、; longlongValue; shortshortValue; floatfloatValue; doubledoubleValue; flag=true; yesChar='y'; finByte=30; intValue=-7000; longValue=200l; shortValue=20XX0; floatValue=; doubleValue=floatValue*floatValue; ( (布尔类型变量flag= (字符型变量yesChar= (
7、字节型变量finByte= (整型变量intValue= (长整型变量longValue= (短整型变量shortValue= (浮点型变量floatValue= (双精度浮点型变量doubleValue= }//endmain} //习题import*;classPubTest1{privateintivar1;privatefloatfvar1,fvar2;publicPubTest1{ fvar2=;} publicfloatsum_f_I{ fvar2=fva
8、r1+ivar1; returnfvar2;} publicvoidprint{ (} publicvoidsetIvar1(intivalue){ ivar1=ivalue;} publicvoidsetFvar1(floativalue){ fvar1=ivalue;}} publicclassPubMainTest{ publicstaticvoidmain(Stringa
此文档下载收益归作者所有