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

绿色编程的作业

发布时间: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++编程作业,怎么写

阅读全文

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

热点内容
什么app抠图好用免费的 浏览:281
文电通pdfgold 浏览:853
上传图片的时候怎么压缩 浏览:31
千寻服务器地址 浏览:812
ssh命令教程视频 浏览:401
苹果商店怎么更新所有app 浏览:34
电影香港加密 浏览:595
压缩机毛细管滴水 浏览:850
可视化编程网页 浏览:389
工厂附近租房用什么app 浏览:186
老板改需求甩锅程序员 浏览:657
乐猫app是什么平台 浏览:922
方舟手游如何修改服务器后台 浏览:815
程序员考试教程 浏览:219
文件名修改为文件夹的名字批处理 浏览:251
拍照程序员 浏览:827
wps怎么把pdf转jpg 浏览:217
自拍用什么app做的艺术照 浏览:169
h3c无线配置命令 浏览:515
linux代码阅读工具 浏览:160