Java

来源:互联网 发布:javascript div 编辑:程序博客网 时间:2024/06/05 02:09
public class User {public static void main(String[] args) {// TODO Auto-generated method stub//Vehic car1,car2;Vehic car1=new Vehic();Vehic car2=new Vehic();car1.setpower(128);car2.setpower(76);System.out.println("car1的功率是:"+car1.getpower());System.out.println("car2的功率是:"+car2.getpower());car1.speedup(80);car2.speedup(80);System.out.println("car1的速度是:"+car1.getspeed());System.out.println("car1的速度是:"+car1.getspeed());car1.speedown(10);car2.speedown(20);System.out.println("car1的速度是:"+car1.getpower());System.out.println("car1的速度是:"+car1.getpower());}}public class Vehic {double speed;//速度int power;//功率void speedup(int s){//减速功率power=power+s;}void speedown(int b){//减速功能power=power-b;}void setpower(int n){//设置功率power=n;}int getpower(){//获取功return power;}double getspeed(){//返回功率return speed;}}public class Family {T homeTV;void buyTV(T tv){homeTV=tv;}void remotecontrol(int m){homeTV.setchannel(m);}void seeTV(){homeTV.showprogram();}}public class Main {public static void main(String[] args) {T haierTV=new T();haierTV.setchannel(5);System.out.println("haierTV看的频道是:"+haierTV.getchannel());Family zhangsanfamily=new Family();System.out.println("不能收看"+channel+"频道");zhangsanfamily.seeTV();int m=2;System.out.println("zhangsanfamily将频道更换为:"+m+"频道");zhangsanfamily.remotecontrol(m);System.out.println("不能收看"+channel+"频道");}}public class T {int channel;void setchannel(int s){if(s>=1){channel=s;}}int getchannel(){return channel;}void showprogram(){switch(channel){case 1 : System.out.println("综合频道");case 2 : System.out.println("经济频道");case 3 : System.out.println("文艺频道");case 4 : System.out.println("国际频道");case 5 : System.out.println("体育频道");default: System.out.println("不能收看"+channel+"频道");}}}

原创粉丝点击