zoukankan      html  css  js  c++  java
  • 电视练习

    public class FormatTest {
    /*public static int maxStringLength;

    public static double minSize;*/

    private static int maxStringLength;

    private static double minSize;

    public static int getMaxStringLength() {
    return maxStringLength;
    }

    public static void setMaxStringLength(int maxStringLength) {
    FormatTest.maxStringLength = maxStringLength;
    }

    public static double getMinSize() {
    return minSize;
    }

    public static void setMinSize(double minSize) {
    FormatTest.minSize = minSize;
    }

    public static boolean testStringLength( String a){
    if(a.length()<=maxStringLength){
    return true;
    }else{
    return false;
    }
    }

    public static boolean testDouble(double b){
    if(b>=minSize){
    return true;
    }else{
    return false;
    }
    }
    }

    再创建一个类

    public class TestProgram {

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner s=new Scanner(System.in);
    System.out.println("请输入一个字符串");
    String a=s.next();
    System.out.println("请输入一个数");
    double b=s.nextDouble();

    /*FormatTest ft = new FormatTest();
    ft.maxStringLength=12;
    ft.minSize=100;

    System.out.println(ft.testStringLength(A));
    System.out.println(ft.testDouble(b))*/

    FormatTest.setMaxStringLength(12);
    FormatTest.setMinSize(100.000);

    System.out.println(FormatTest.testStringLength(a));
    System.out.println(FormatTest.testDouble(b));
    }

    }

    再创一个类

    public class Television {
    private int channel;
    private int volume;

    public int getChannel() {
    return channel;
    }

    public void setChannel(int channel) {
    if(channel>=2&&channel<=999){

    this.channel = channel;
    }else{
    System.out.println("没有这个频道,请重新开始");
    }

    }

    public int getVolume() {
    return volume;
    }

    public void setVolume(int volume) {
    if(volume>=0&&volume<=10){
    this.volume = volume;
    }else{
    System.out.println("输入错误,请重新输入音量");
    }

    }

    public Television(){

    }

    public Television(int channel,int volume ){
    this.channel=channel;
    this.volume=volume;
    }
    }

    最后创一个类运行

    public class WatchTelevision {

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner s=new Scanner(System.in);
    System.out.println("请输入频道");
    int channel=s.nextInt();
    System.out.println("请调节音量");
    int volume=s.nextInt();

    Television tv=new Television();
    tv.setChannel(channel);
    tv.setVolume(volume);


    if(tv.getChannel()>=2&&tv.getChannel()<=999){

    System.out.println("你正在收看"+tv.getChannel()+"频道");
    System.out.println("当前正在播放:12345");
    }else{
    System.out.println("请输入正确频道");
    }

    if(tv.getVolume()>=0&&tv.getVolume()<=10){
    System.out.println("当前音量为"+tv.getVolume());
    }else{

    System.out.println("没有此音量");
    }

    }

    }

    感觉还是有点不熟悉

  • 相关阅读:
    进行编译时提示'error: unrecognized command line option "-std=gnu11"'如何处理?
    linux shell中如何批量添加一行内容到某些文件的末尾?
    linux内核中的电源管理接口
    linux内核中i2c驱动中slave模式接口的调用
    git clone时报错“Failed to connect to 127.0.0.1 port 2453: Connection refused”如何处理?
    第 8 章 输入框和导航组件
    第 7 章 图标菜单按钮组件
    第 6 章 辅组类和响应式工具
    第 5 章 栅格系统
    第 4 章 表单和图片
  • 原文地址:https://www.cnblogs.com/whj1986556646/p/5539783.html
Copyright © 2011-2022 走看看