/*烟台大学计算机学院学生
*All right reserved.
*文件名称:java--TV类最终版
*作者:杨飞
*完成日期:2014年10月2日
*版本号:v1.0
*对任务及求解方法的描述部分:java--TV类最终版
*我的程序:*/
public class TV {
private Channel []a ;
private String srand;
public TV()
{
}
public TV( String srand)
{
this.srand = srand;
}
public Channel[] getA() {
return a;
}
public void setA(Channel[] a) {
this.a = a;
}
public String getSrand() {
return srand;
}
public void show(int m)
{
System.out.println("现在的所观看的频道号"+a[m-1].getChannelNumber()+"频道名"+a[m-1].getChannalText());
}
public void channalchange(int m)
{
show(m);
}
}
class Family
{
private TV ss;
public void buyTV(TV tv)
{
ss=tv;
}
public void remoteControl(int m)
{
ss.channalchange(3);
}
public void setTV(int m)
{
ss.show(3);
}
}
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()
{
return channelNumber;
}
public String getChannalText()
{
return channelText;
}
}
class test
{
public static void main(String []args)
{
TV s =new TV("海尔");
Family zhangshan=new Family();
zhangshan.buyTV(s);
System.out.println("zhangshan买了一台"+s.getSrand()+"电视");
Channel []tvchannal = new Channel[3];
tvchannal [0]= new Channel (1,"山东卫视");
tvchannal [1]= new Channel (2,"中央一台");
tvchannal [2]= new Channel (3,"湖南卫视");
s.setA(tvchannal);
System.out.println("正在播出的频道:");
s.show(1);
System.out.println("Tv类的转换之后的频道:");
s.channalchange(2);
System.out.println("Family类的转换之后的频道:");
zhangshan.remoteControl(3);
}
}
java--TV类最终版
最新推荐文章于 2024-01-19 08:56:12 发布