- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
面向对象练习题(Object oriented exercises).doc
面向对象练习题(Object oriented exercises)
1. [exercises] member variables of class:
Guessing game: a class A has a member variable V, with an initial value of 100. Define a class and guess the member variable V of a class A. If its big, then its big, small, then its small. Equal to prompt guess success.
Public class A{
Private int v;
V=100;
}
Import util.java.Scanner;
Public class Test{
Public statuc void main (String[] args) {
Scanner sc=new Scanner (System.in);
Int number= (int) (Math.random () *100);
A a = new A ();
Int v=sc.nextInt ();
If (vnumber) {
System.out.println (too big);
}else if (v==number) {
System.out.println (success);
}else if (vnumber) {
System.out.println (too small);
}
}
}
2. [exercises] member variables of class:
Please define a class of transport vehicles (Vehicle):
Attributes: speed (speed), volume (size), etc.
Methods: move (move ()), set speed (setSpeed (int speed)), accelerate speedUp (), decelerate speedDown (), and so on
Finally, a vehicle object is instantiated in the main () of the test class Vehicle, and the value of the speed, size is initialized by the method, and printed out. In addition, the method of acceleration and deceleration is used to change the speed.
Public class Vehicle{
Public String speed;
Public double size;
Public move () {
System.out.println (mobile method);
}
Public void setSpeed (int speed) {
This.speed=speed;
System.out.println (setting speed);
}
Public speedUp () {
System.out.println (acceleration);
}
Public speedDown () {
System.out.println (deceleration);
}
}
Public class Test{
Public statuc void main (String[] args) {
Vehicle v = new Vehicle ();
}
}
Class variables, methods and construction methods for class 3. exercises
In a program, time is often operated, but there is no temporal type of data. Well, we can implement a time class ourselves to meet the needs of the program.
Define a class named MyTime, which should have three integer members: time (hour), sub (minute), second (second), in order to ensure the safety
您可能关注的文档
- D打印创新平台 ,滕先生:.doc
- 饥荒修改代码(Code for famine modification).doc
- 用蛮力法动态规划法和贪心法求解背包问题.doc
- 刑法学选择题(看一下,有印象考试就有)(Selective questions in Criminal Law (see, impression test)).doc
- 婚礼送礼感谢信.doc
- 广元利州中专D全景方案.doc
- 利用探地雷达技术获取与土壤盐渍化程度相关的信息.doc
- 平板电脑联发科老十核成了救火队员?!.docx
- 结构位移(Structural displacement).doc
- 2009职称英语a综合(2009 title English a synthesis).doc
- rcrss中基于粒子滤波算法的火势预测研究(Research on fire prediction based on particle filter algorithm in rcrss).doc
- 供排水工艺--安全知识(Water supply and drainage technology -- safety knowledge).doc
- FTC-III发电机特性测试仪仪器系统软件资料.doc
- 塑料 常用物理性能简释(Simple explanation of common physical properties of plastics).doc
- oracle获取存储过程信息(Oracle gets stored procedure information).doc
- hchuaweicom交换机端口汇聚配置指南(Port sink configuration guide for hchuaweicom switches).doc
- 新理念英语上机测试(华工版)bu-d(New concept English computer test (Chinese version) bu-d).doc
- mn第课又画又做又印.doc
- 聚仙堂(The hall of Poly).doc
- 化学反应速率 化学平衡 练习题(Chemical reaction rate chemical balance exercises).doc
文档评论(0)