• 电视练习


    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("没有此音量");
    }

    }

    }

    感觉还是有点不熟悉

  • 相关阅读:
    halconfind_shape_model形状模板匹配
    halcondistance_pp求两点的距离
    halcondistance_lr计算直线和区域之间的距离
    halconcount_seconds统计程序运行时间
    halcondistance_cc计算两个轮廓之间最小和最大的距离
    halconcreate_ncc_model创建NCC模板
    halcondistance_ss计算两条直线之间的距离
    halcondistance_pr计算点和区域之间的距离
    halcondistance_pl计算点和直线之间的垂直距离
    数仓如何设置大小写不敏感函数
  • 原文地址:https://www.cnblogs.com/whj1986556646/p/5539783.html
Copyright © 2020-2023  润新知