TV.java
public class TV {
private int channel;
public void showProgram(){
System.out.println("频道:"+channel);
}
public void setchannel(int channel){
this.channel=channel;
}
public int getchannel(){
return channel;
}
}
Famliy.java
public class Famliy {
private TV tv;
public void buyTV(TV tv){
this.tv=tv;
}
public void remoteContron(int m){
tv.setchannel(m);
}
public void seeTV(){
tv.showProgram();
}
}
FamilyText.java
import java.util.*;
public class FamilyText{
public static void main(String[] args) {
Famliy wangming=new Famliy();
TV tv=new TV();
wangming.buyTV(tv);
wangming.seeTV();
System.out.println("请选择:");
Scanner scanner=new Scanner(System.in);
int channel=scanner.nextInt();
wangming.remoteContron(channel);
wangming.seeTV();
}
}