永发信息网

作业来的,设计一个名为Fan的类模拟风扇。

答案:4  悬赏:0  手机版
解决时间 2021-01-29 15:39
作业来的,设计一个名为Fan的类模拟风扇。
最佳答案
public class Fan {

private final int SLOW = 1;
private final int MEDIUM = 1;
private final int FAST = 1;
private int speed = SLOW;
private boolean on = false;
private double radius = 5;
private 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;
}

public String getColor() {
return color;
}

public void setColor(String color) {
this.color = color;
}

public Fan(){};

public Fan(int speed,boolean on,double radius,String color){
this.speed = speed;
this.on = on;
this.radius = radius;
this.color = color;
}

@Override
public String toString() {
if(on==true){
return "该风扇的速度为:" + speed +";颜色是:"+color+";半径是:"+radius;
}else{
return "fan is off;"+"该风扇的颜色是:"+color+";半径是:"+radius;
}
}

}

uml图自己画,呵呵
全部回答

UML如果需要的话稍后给你画吧,吃饭去啦 呵呵 这个程序仅供参考
public class Fan {
 private final int SLOW = 1;
 private final int MEDIUM = 2;
 private final int FAST = 3;
 private int speed = SLOW;
 private boolean isOn  = false;
 private double radius =5.0;
 private String color = "blue";
 public Fan()
 {
  
 }
 public int getSpeed()
 {
  return speed;
 }
 public void setSpeed(int _speed)
 {
  if(_speed>=3)
  speed = FAST;
  else if(_speed<=1)
  speed = SLOW;
  else 
  speed = MEDIUM;
  
 }
 
  public double getRadius()
 {
  return radius;
 }
 public void setRadius(int _radius)
 {
  radius = radius;
 }
 
 public void setColor(String _color)
 {
  color = _color;
 }
 
 public String getColor()
 {
  return color;
 }
 
 public boolean isOn()
 {
  return isOn;
 }
  public void run()
  {
   if(!isOn())
   isOn = true;
  }
  
  //@Overwrite
  public String toString()
  {
   if(isOn())
   return "Fan : speed= "+speed+" color= "+color+" radius = "+radius;
   else
   return "This Fan is off! And the color of this Fan is "+color+" ,the radius of this Fan is "+radius;
  }
  
  public static void main(String []args)
  {
   Fan f1=new Fan();
   f1.setColor("yellow");
   f1.setRadius(10);
   f1.setSpeed(3);
   f1.run();
   Fan f2 = new Fan();
   f2.setSpeed(2);
   f2.setRadius(5);
   System.out.println(f1);
   System.out.println(f2);
   
  }
 }
你拿200分就要回答这些问题,,,,直接送我得了~~~~~~~
1000分待考虑
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
你们喜欢张艺兴吗?觉的他是什么样子的明星
【什么是团队】合作的意思团队意识的意思合作
描写春天的诗句和古诗1~4年级谢谢!
平云的意思是什么啊?知道的请说下!
24张纸牌怎样连续翻完,,,如下 * * * *
氙气灯 汉雷3 谁懂 怎么样 请教
YUQ优口公司成立多久了?
番禺交通违章学习是什么时间
遐叶的意思是什么啊?知道的请说下!
周逢俊的画价格,能卖多少钱,拍卖高成交价格
如何挑选螃蟹
奇迹电玩城地址在什么地方,想过去办事
川川的意思是什么啊?知道的请说下!
人民网没有站内搜索,怎么回事?怎样搜索人民
我玩英雄联盟已经快两年了,拿过无数次四杀就
推荐资讯
悦翔v7在关闭车门后电子防盗指示灯闪烁正常吗
从网上下了一个64位的win7系统,我的电脑是32
什么办法可以推迟月经
魔兽世界虬达多久刷新
我的数码相机点击拍照就显示:“存储媒体”,
【江淮之蜂蟹】江淮之蜂蟹
衣服上的黑麻点怎么去除干净
求《尸体派对影之书》主题曲《花开之处》歌词
为什么小米低音炮怎么链接不了海尔电视
单选题在四川汶川大地震中,中学生薛枭被埋在
在上海华山医院做激光祛雀斑大概什么价格
星星海DanceStudio地址在什么地方,想过去办
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?