‘壹’ 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++编程作业,怎么写