javastringboolean
模拟实现电风扇,可以调 3 档速度(慢速、中速、快速);开关按钮;定时吹风;描述
风扇的扇叶大小、颜色等。
设计Fan 类,属性包括:3 个常量 SLOW (1)、MEDIUM(2)、FA ST(3)代表风扇的
速度;1 个int 属性speed 指定速度,默认值为 SLOW ;1 个boolean属性 on 指定开关机,默
认值false ;1 个double 属性 radius 指定风扇扇叶大小;1 个String 属性 color指定扇叶颜色,
默认值为 blue 。方法包括这些属性的访问器、构造函数、重写 Object 类的 toString() 和equals()
Java编程谢谢大家,急用!!!!!!!!!
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- baibing321 2015-10-15 00:45关注
public class Fan { public Fan() {} public static final int SLOW = 1; public static final int MEDIUM = 2; public static final int FA = 3; public int speed = SLOW; public boolean on = false; public double radius = 0.0d; public String color = "blue"; public int getSpeed() { return speed; } public void setSpeed(int speed) { this.speed = speed; } public boolean isOn() { return on; } public void setOn(boolean on) { this.on = on; } public double getRadius() { return radius; } public void setRadius(double radius) { this.radius = radius; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((color == null) ? 0 : color.hashCode()); result = prime * result + (on ? 1231 : 1237); long temp; temp = Double.doubleToLongBits(radius); result = prime * result + (int) (temp ^ (temp >>> 32)); result = prime * result + speed; return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Fan other = (Fan) obj; if (color == null) { if (other.color != null) return false; } else if (!color.equals(other.color)) return false; if (on != other.on) return false; if (Double.doubleToLongBits(radius) != Double .doubleToLongBits(other.radius)) return false; if (speed != other.speed) return false; return true; } @Override public String toString() { return "Fan [speed=" + speed + ", on=" + on + ", radius=" + radius + ", color=" + color + "]"; } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 聚类分析或者python进行数据分析
- ¥15 逻辑谓词和消解原理的运用
- ¥15 三菱伺服电机按启动按钮有使能但不动作
- ¥15 js,页面2返回页面1时定位进入的设备
- ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
- ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
- ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
- ¥20 腾讯企业邮箱邮件可以恢复么
- ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
- ¥15 错误 LNK2001 无法解析的外部符号