/*烟台大学计算机学院学生
*All right reserved.
*文件名称:java--家庭电视类(加类修改版)
*作者:杨飞
*完成日期:2014年9月2日
*版本号:v1.0
*对任务及求解方法的描述部分:java--家庭电视类(加类修改版)
*我的程序:*/
public class TV {
private Channel []a=new Channel [3] ;
private int channal;
public TV()
{
}
public TV(int channal )
{
this.channal=channal;
}
public void setChannal(int n)
{
channal=n;
}
public int getChannal()
{
return channal;
}
public void showProgram()
{
switch(channal)
{
case 1: a[0]=new Channel(channal,"山东卫视");
System.out.println(a[0].getChannalText());
System.out.println("正在直播篮球比赛");
break;
case 2: a[1]=new Channel(channal,"CCTV1");
System.out.println(a[1].getChannalText());
System.out.println("正在直播民生问题的新闻");
break;
case 3: a[2]=new Channel(channal,"CCTV5");
System.out.println(a[2].getChannalText());
System.out.println("正在直播电视剧");
break;
default:
System.out.println("你的电视台没有这个频道,赶快换个吧");
}
}
public void channalchange(int m)
{
channal=m;
}
}
class Family
{
private TV a;
public Family()
{
}
public void buyTV(TV tv)
{
a=tv;
}
public void remoteControl(int m)
{
a.setChannal(m);
}
public void setTV()
{
a.showProgram();
}
}
class Channel
{
private int channelNumber;
private String channelText;
public Channel()
{
}
public Channel(int channelNumber,String channelText)
{
this.channelNumber = channelNumber;
this.channelText =channelText;
}
public void setChannelNumber(int m)
{
channelNumber=m;
}
public int getChannelNumber(int m)
{
return channelNumber;
}
public String getChannalText()
{
return channelText;
}
}
class test
{
public static void main(String []args)
{
TV s = new TV(2);
System.out.println("现在的频道显示:");
s.showProgram();
System.out.println("通过家庭类的调换节目");
TV s1 = new TV();
Family a=new Family();
a.buyTV(s1);
a.remoteControl(1);
a.setTV();
System.out.println("通过频道类的调换节目");
TV s2 = new TV();
s2.channalchange(3);
s2.showProgram();
}
}
运行结果:
心得体会:呵呵