首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
阅读以下说明和Java程序,将应填入(n)处的字句写在对应栏内。 [说明] 下面程序输出一个矩形面积,以及矩形区域上的假想的作物产量。 [Java程序] public class MainJava { public
阅读以下说明和Java程序,将应填入(n)处的字句写在对应栏内。 [说明] 下面程序输出一个矩形面积,以及矩形区域上的假想的作物产量。 [Java程序] public class MainJava { public
admin
2010-12-16
66
问题
阅读以下说明和Java程序,将应填入(n)处的字句写在对应栏内。
[说明]
下面程序输出一个矩形面积,以及矩形区域上的假想的作物产量。
[Java程序]
public class MainJava {
public static void main(String[] args){
Lot_size small=new Lot_size();
Lot_size medium=new Lot_size();
small.set(5,5,5,25);
medium.set(10,10,10,50);
System.out.println("For a small lot of area"
+small.get_area()+"\n");
System.out.println("the actual crops are $"
+small.get_data2()+"\n");
System.out.println("and ideal crops are $"
+small.get data()+"\n");
System.out.println("For a medium lot of area"
+medium.get_area()+“\n”);
System.out.println("the actual crops are $"
+medium.get_data2()+"\n");
System.out.println ("and ideal crops are $"
+medium.get_data()+"\n");
}
}
class Crop_assessment{
private int actual_crop;
private int ideal_crop;
public void set(int in_actual,int in ideal){
actual_crop=in_actual;
ideal_crop=in_ideal;
}
public int get_actual_crop(){return (1) ;}
public int get_ideal_crop()(return (2) ;}
}
class Lot_size{
private int length;
private int width;
private Crop_assessment crop= (3) ;
public void set(int 1,int W,int a,int i){
length=1;
width=W;
crop.set(a,i);
}
public int get_area(){return length*width;}
public int get_data()freturn (4) ;}
public int get_data2()(return (5) ;}
}
选项
答案
(1) return actual_crop (2) return ideal_crop (3) new Crop_assessment() (4) crop.get_ideal_crop (5) crop.get_actual_crop()
解析
本题以Java语言为载体,考查面向对象程序设计中的几个重要概念—类的嵌套及函数的使用。
本题的功能是通过已定义的粮食收成类定义了一个计算特定矩形域上粮食收成的类,在主函数中定义了两个对象,并调用了相应的函数,来输出理想和实际的粮食产量。
首先,由于Crop assessment定义的成员数据缺省为私有的,所以想要获得实际和理想的粮食产量,要通过两个公有成员函数,所以(1)处应填入“return actual_crop”,(2)处应填入“return ideal_crop”。
其次,在类Lot size中,由于我们要反映矩形域上的粮食产量,所以我们在类中嵌套定义了一个类,Java中对象需要实例化,故(3)应填入“new Crop_assessment()”。
最后,由于我们想通过Lot_size类中的get_data和get_data2函数得到粮食产量,但由于这两个成员数据是私有函数,所以我们必须通过定义的对象调用它,所以(4)应填入“crop.get_ideal_crop()”,(5)应填入“crop.get_actual_crop()”。
转载请注明原文地址:https://kaotiyun.com/show/OBjZ777K
本试题收录于:
程序员下午应用技术考试题库软考初级分类
0
程序员下午应用技术考试
软考初级
相关试题推荐
在Word2007中,为使内容更加醒目,文章更具有条理性,可在若干段落前面添加__________。
在Excel2007中,在单元格A1中输入函数“=POWER(2,3)/MAX(1,2,4)”,按回车键后,则A1单元格中的值为__________。
统计报表中常包括填表说明,以指导填表者填写。填表说明中一般不包括______。
下列不属于著作权保护的是______。
在统计学中,用来衡量一个样本中各个数据波动大小的量是______。
在用Word软件编辑文档时,若误删除了一个数据,随后可使用______命令进行恢复。
下列选项中,衡量数据校验人员业务水平的主要指标是(20)。
某企业的大数据工程项目包括如下四个阶段的工作:①数据获取,②数据清洗与整理,③数据分析,④数据展现。一般来说,工作量较大、花费时间较长的阶段是______(1),技术含量最高的阶段是______(2),准备向有关部门递交成果的阶段是______(3)。
某工厂信息处理技术员设计了如下统计表:该表设计中包含的问题以及改进方法是______。
随机试题
A.脓性B.血性C.黄色水样D.奶油状E.豆腐渣样子宫黏膜下肌瘤、宫颈癌、宫体癌、输卵管癌病变组织变性坏死,阴道分泌物可呈
新生儿出生后进行Apgar评分的评价指标不包括
下列有关竞争能力分析的描述正确的是()。
某煤矿为增值税一般纳税人,主要从事煤炭开采、原煤加工、洗选煤生产业务,2019年4月发生下列业务:(1)采用分期收款方式销售自行开采的原煤取得不含税销售额45000元,合同规定,货款分两个月支付,4月15日支付60%,其余货款于5月15日支付。由于购货方
我国城市基础设施管理的综合机构是()。
侵占罪:是指以非法占有为目的,将为他人保管的财物或者其他遗忘物、埋藏物占为已有,数额较大且拒不交还的行为。?根据以上的定义,下面哪种行为是典型的侵占罪( )。
[*]
Imagineaworldinwhichthereweresuddenlynoemotion--aworldinwhichhumanbeingscouldfeelnoloveorhappiness,noterro
Throughouthistorymanhasobservedsuchnaturalcyclesastherisingandsettingofthesun,theebbandflowoftheoceantide
Sometimes,whatlookslikeimprovedefficiencyinpost-secondaryeducationisreallyfallingquality.Ifwewantourchildrento
最新回复
(
0
)