java模拟题专项训练.pdfVIP

  • 1
  • 0
  • 约4.53千字
  • 约 3页
  • 2025-04-02 发布于广东
  • 举报

1.DefineaJavamethodtoprintthenumberofvowelcharacterandthenumberofspacesinagiven

string.

Vowelsincludea,A,e,E,i,I,o,O,u,U.

给定一个字符串,分别统计其中所包含的元音的个数和空格的个数。

元音:a,A,e,E,i,I,o,O,u,U。

2.Defineamethodtocollectthecommonelementsintwoarraysofintegers.

int[]getCommonElements(int[]arr1,int[]arr2)

编程返回由两整型数组arr1和arr2中共同的元素组成的数组。

int[]getCommonElements(int[]arr1,int[]arr2)

3.DefineaBankAccountclass,whichcontains:

(1)Bankaccountattributes:username,accountnumber,andbalance.

(2)Constructionmethods:atleasttwoconstructionmethods,callingmulti-parameterconstruction

methodstodefineno-parameterconstructionmethods.Definethegetmethodandsetmethodof

eachproperty.

(3)Definemethods:deposit(floatamount)withdraw(floatamount).OverridethetoString()

methodtooutputaccountandbalanceinformation.

(4)Instantiatethisclassinthemain()method,andcallthetoString()methodtocompletetheoutput

ofvariousinformation.

编写一个BankAccount类表示银行账号,该类中包含:

(1)银行账号信息:用户名name、账号number、余额balance。

(2)构造方法:至少两种构造方法,利用多参的构造方法定义无参的构造方法。

定义各属性的get方法和set方法。

(3)定义示例方法:存款deposit(amount)方法、取款withdraw(amount)两个实例方法。重写

toString()方法,输出账号和余额信息。

(4)在main()方法中实例化这个类,调用toString()方法完成各项信息的输出。

4.(1)DesigntheabstractclassesCar,includingfields:carId,carName;amulti-parameter

constructor;theget-methodofeachattribute,theabstractgetCapacity();

(2)DesigninterfaceIHumanNum,includinggetIHumanNum()andsetIHumanNum()methods.

(3)DesignsubclassePassagecarinheritstheCarclassandimplementstheIHumanNuminterface,

definetheprivateattributeinthumanNum.Thisconstructorinheritsthesuperconstructorand

initializetheattributehumanNum.OverridethemethodgetCapacity():printNumberofpeopleon

board:+humanNum+person;

(4)Designthemain()method.Anarraynamedcarsisusedtostor

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档