import java.util.Scanner;
public class TV {
private int channel;
public void setChannel(int c)
{
this.channel=c;
}
public int getChannel()
{
return channel;
}
public void showProgram()
{
System.out.println("1.CCTV1"+'\n'+"2.CCTV2"+'\n'+"3.CCTV3"+'\n'+"4.CCTV4"+'\n'+"5.CCTV5");
System.out.println("请输入你要看的节目标号:");
Scanner reader=new Scanner(System.in);
int c=reader.nextInt();
switch(c)
{
case 1:System.out.println("正在观看CCTV1");
break;
case 2:System.out.println("正在观看CCTV2");
break;
case 3:System.out.println("正在观看CCTV3");
break;
case 4:System.out.println("正在观看CCTV4");
break;
case 5:System.out.println("正在观看CCTV5");
break;
default: System.out.println("超出收到的频道数量");
}
}
}
public class family {
private TV tv=new TV();
public void buyTV(TV tv)
{
System.out.println("买了一台海尔电视机");
this.tv=tv;
}
public void remoteControl(int m)
{
tv.setChannel(m);
}
public void seeTV()
{
tv.showProgram();
}
}
public class Kan {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
TV t=new TV();
family f=new family();
f.buyTV(t);
t.showProgram();
f.remoteControl(1);
t.showProgram();
}
}
JAVA看电视
最新推荐文章于 2021-03-22 01:31:28 发布