赞
踩
import java.util.Scanner; public class S3_1 { public static class TV{ int tvChannel; int tvVolume; int tvSwitch; public void ChangetvChannel(int tvChannel){ this.tvChannel=tvChannel; System.out.println("现在是"+tvChannel+"台"); } public void AdjusttvVolume(int changetvvolume) { if(changetvvolume==1){ this.tvVolume++; System.out.println("现在的音量是"+tvVolume); if(tvVolume>=5){ System.out.println("音量已经最大了!"); } } else if(changetvvolume==2){ this.tvVolume--; System.out.println("现在的音量是"+tvVolume); if(tvVolume<=0){ System.out.println("音量已经最小了!"); } } else{ System.out.println("error!"); } } public void settvSwitch(int tvSwitch){ this.tvSwitch=tvSwitch; if(tvSwitch==1){ System.out.println("TV已打开"); } else if(tvSwitch==0){ System.out.println("TV已关闭"); }else{ System.out.println("error!"); } } } public static void main(String[] args) { TV tv = new TV(); System.out.println("TV现处于关闭状态,请进行如下选择:"); System.out.println("1--打开TV"); System.out.println("0--关闭TV"); Scanner sc=new Scanner(System.in); int select=sc.nextInt(); tv.settvSwitch(select); if(select==0){ System.out.println("程序已退出!"); }else { while (select!=0) { System.out.println("TV现处于开启状态,请进行如下选择:"); System.out.println("1--换台"); System.out.println("2--调整音量"); System.out.println("0--关闭TV"); select=sc.nextInt(); switch (select) { case 1: System.out.println("请输入你想要换的台数:"); int tvChannel = sc.nextInt(); tv.ChangetvChannel(tvChannel); break; case 2: System.out.println("1--增大音量"); System.out.println("2--减小音量"); int changetvvolume = sc.nextInt(); tv.AdjusttvVolume(changetvvolume); break; case 0: tv.settvSwitch(select); break; default: System.out.println("error!"); } } } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。