这个程序怎么测试

wang1610912518 2017-04-12 08:31:02
package Romote;

/*
* 功能:通过遥控控制客厅电视,卧室电灯
* 类:
* 遥控器类(接口)
* 成员方法:
* 扩展:
* 客厅电视:
* 成员方法:打开电视
* 关闭电视
* 卧室电灯:
* 成员方法:打开电灯
* 关闭电灯
*
*/
interface Command { // 接口类Command,为电灯和电视提供开、关的命令集
abstract void on(); // 电器打开

abstract void off(); // 电器关闭

}

class Light { // 电灯类
private int degree;

public int getturnLight(){
return degree;
}
public void setturnLight(int degree) {// 调整灯光亮度,0表示关灯,100表示亮度最大
this.degree=degree;
if(degree==0){
System.out.println("电灯关闭");
}else if(degree==100){
System.out.println("电灯亮度达到最大");
}
}
}

class TV {
private int channel;
public int getChannel(){
return channel;
}
public void setChannel(int channel) {
this.channel=channel;
if(channel==0){
System.out.println("电视关闭");
}else if(channel==1){
System.out.println("打开电视");
}
}
}

class romoteController {
protected Command[] commands = new Command[4];

public void onPressButton(int button) {// 按钮被按下时,执行命令对象的命令
if (button % 2 == 0)
commands[button].on();
else
commands[button].off();
}

public void setCommand(int button, Command command) {
commands[button] = command; // 设置每个按钮应对应得命令对象
}
}

class LightCommand implements Command {
protected Light light; // 指向要控制的电灯对象

public void on() {
System.out.println("电灯打开");
}

public void off() {
System.out.println("电灯关闭");
}

public LightCommand(Light light) {
this.light=light;
light.getturnLight();
light.setturnLight(100);
}
}

class TVCommand implements Command {
protected TV tv;
protected int channel;

public void on() {
System.out.println("电视打开");
}

public void off() {
System.out.println("电视关闭");
}

public TVCommand(TV tv, int channel) {

tv.getChannel();
tv.setChannel(0);
}
}
public class Romote{
public static void main(String[] args) {
//创建对象
// Command c=new LightCommand();

// Command c=new TVCommand();

// romoteController r=new romoteController();

}
}
...全文
129 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
baidu_33864721 2017-04-13
  • 打赏
  • 举报
回复
public static void main(String[] args) {
		//创建灯
		Light light=new Light();
		//初始化灯为关闭状态
		light.setturnLight(0);
		//创建灯的遥控器
		Command c = new LightCommand(light);
		//打开灯
		c.on();
	}

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧