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

绿色编程的作业

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

阅读全文

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

热点内容
哪种加密算法是非对称算法 浏览:989
多文件夹加序号 浏览:844
编译程序包含汇编程序吗 浏览:895
游戏源码搭建一条龙 浏览:192
宋金pdf 浏览:807
服务器为什么需要内存池 浏览:526
php与jquery开发实例 浏览:289
编程大世界故事漫画 浏览:983
北漂程序员出车祸 浏览:914
亚马逊为什么用云端服务器 浏览:65
程序员审核职位 浏览:385
德龙空调压缩机 浏览:780
红旗app如何注册新账户 浏览:360
惯导pdf 浏览:606
c程序员的平均工资 浏览:58
微小店源码 浏览:801
编译原理答题题库 浏览:169
ubuntu编程入门 浏览:301
antbuild命令 浏览:771
怎么订阅服务器 浏览:593