导航:首页 > 编程语言 > 绿色编程的作业

绿色编程的作业

发布时间:2023-02-24 14:57:16

‘壹’ Java编程作业,急用

以下是源代码和运行结果截图,如果哪里有问题的话可以来找我。

classPet{

intage;

intweight;

publicPet(intage,intweight){

super();

this.age=age;

this.weight=weight;

}

publicvoidshowInfo(){

System.out.println("myweightis"+this.weight+"andmyageis"+this.age);

}

publicintgetWeightInfo(){

returnthis.weight;

}

publicintgetAgeInfo(){

returnthis.age;

}

}

interfaceEatable{

publicabstractvoidbeEatted();//默认为public和abstract

}

classCatextendsPet{

publicCat(intage,intweight){

super(age,weight);

//TODOAuto-generatedconstructorstub

}

privateintcry;

publicvoidshowInfo(){

System.out.println("I'maCat,myweightis"+this.weight+"andmyageis"+this.age);

}

publicintgetWeightInfo(){

returnsuper.getWeightInfo();

}

publicintgetAgeInfo(){

returnsuper.getAgeInfo();

}

}

{

publicDog(intage,intweight){

super(age,weight);

//TODOAuto-generatedconstructorstub

}

privateintcry;

publicvoidshowInfo(){

System.out.println("I'maDog,myweightis"+this.weight+"andmyageis"+this.age);

}

publicintgetWeightInfo(){

returnsuper.getWeightInfo();

}

publicintgetAgeInfo(){

returnsuper.getAgeInfo();

}

publicvoidbeEatted(){

}

}

classFruitimplementsEatable{

publicFruit(Stringcolor,Stringaddress){

super();

this.color=color;

this.address=address;

}

Stringcolor;

Stringaddress;

publicvoidbeEatted(){

System.out.println("I'mbeeneaten!");

}

publicvoidshowInfo(){

System.out.println("mycoloris"+this.color+"andmyaddressis"+this.address);

}

publicStringgetColorInfo(){

returnthis.color;

}

publicStringgetAddressInfo(){

returnthis.address;

}

}

classBananaextendsFruit{

publicBanana(Stringcolor,Stringaddress){

super(color,address);

//TODOAuto-generatedconstructorstub

}

publicvoidbeEatted(){

System.out.println("I'maBanana,I'mbeeneaten!");

}

publicvoidshowInfo(){

System.out.println("I'maBanana,mycoloris"+this.color+"andmyaddressis"+this.address);

}

@Override

publicStringgetColorInfo(){

//TODOAuto-generatedmethodstub

returnthis.getColorInfo();

}

@Override

publicStringgetAddressInfo(){

returnthis.getAddressInfo();

}

}

classAppleextendsFruit{

Stringtype;

publicApple(Stringcolor,Stringaddress,Stringtype){

super(color,address);

this.type=type;

//TODOAuto-generatedconstructorstub

}

publicStringgetType(){

returntype;

}

publicvoidbeEatted(){

System.out.println("I'manapple,I'mbeeneaten!");

}

publicvoidshowInfo(){

System.out.println("I'manApple,mycoloris"+this.color+",myaddressis"+this.address

+"andmytypeis"+type);

}

@Override

publicStringgetColorInfo(){

//TODOAuto-generatedmethodstub

returnthis.getColorInfo();

}

@Override

publicStringgetAddressInfo(){

returnthis.getAddressInfo();

}

}

publicclassPrograms{

publicstaticvoidmain(String[]args){

Catmycat=newCat(10,20);

Dogmydog=newDog(10,24);

Bananamybanana=newBanana("黄色","北京");

Applemyapple=newApple("红色","上海","新品种");

mycat.showInfo();

mydog.showInfo();

mybanana.showInfo();

myapple.showInfo();

mydog.beEatted();

mybanana.beEatted();

myapple.beEatted();

}

}

‘贰’ 编程作业怎么做!

不知道你问的是哪一题

假设是其中最清楚的那一题,如555555最大的三位数

其实这题很简单,如果不考虑性能的话,直接从100开始遍历,定义两个局部变量
假设是int a与int b
弄一个循环,a从100开始,然后b从1开始

a×b如果等于55555,就记录在一个temp变量一面,如果遇到下一个a×b等于555555的组合,就跟temp比,如果比temp记录的数大,就用大的替换掉temp里面小的那一个。

如果a×b大于55555,立即结束本次循环,a+1,跳入下一次循环。

其实还有更简便的方法。。。不过用到一些复杂的数学公式就不说了。

如果要简单粗暴的话,直接开多线程去找,一个线程负责一个区间,比方说100-200,200-300一直到5555500到555555,找到满足a×b=555555的数,而且每次a+5,(因为555555末尾是5,其中一个乘数必定是5,所以以5作为每次循环的步长应该能提升5倍性能)

总之怎么简单粗暴怎么来。

‘叁’ C++编程作业,怎么写

阅读全文

与绿色编程的作业相关的资料

热点内容
数据库查询系统源码 浏览:612
php5314 浏览:352
完美国际安装到哪个文件夹 浏览:664
什么app可以扫一扫做题 浏览:535
程序员编码论坛 浏览:920
淘点是什么app 浏览:655
中国高等植物pdf 浏览:449
51单片机时间 浏览:177
后台如何获取服务器ip 浏览:261
单片机流水灯程序c语言 浏览:230
程序员第二职业挣钱 浏览:235
运行里怎么输入服务器路径 浏览:835
pythonstepwise 浏览:504
刘一男词汇速记指南pdf 浏览:57
php认证级别 浏览:363
方舟编译啥时候推送 浏览:1006
php手机验证码生成 浏览:670
哲学思维pdf 浏览:12
凌达压缩机有限公司招聘 浏览:528
weblogic命令部署 浏览:31