zoukankan      html  css  js  c++  java
  • 标准类的建立,以及用集合对标准类中的元素进行存取操作

    /*

    1.设计一个Movie类,私有成员变量:title(片名),director(导演),type(类型),并生成相应的get/set方法。


    2.定义测试类,在main方法中完成以下要求:

    2.1创建三个Movie对象,分别为” 唐山大地震”,”冯小刚”,”灾难”;”羞羞的铁拳”,” 宋阳”,” 喜剧”; ”集结号”,” 冯小刚”,”历史”;
    2.2将以上3个对象添加到list集合中
    2.3遍历集合,将导演为“冯小刚”的电影按照如下格式打印到控制台上。*/

    Movie标准类:

    public class Movie {
        private String title;
        private String director;
        private String type;
        
        public String getTitle() {
            return title;
        }
        public void setTitle(String title) {
            this.title = title;
        }
        public String getDirector() {
            return director;
        }
        public void setDirector(String director) {
            this.director = director;
        }
        public String getType() {
            return type;
        }
        public void setType(String type) {
            this.type = type;
        }
        public Movie(String title, String director, String type) {
            this.title = title;
            this.director = director;
            this.type = type;
        }
        public Movie() {
        }
        
    }

    测试类:

    import java.util.ArrayList;
    
    public class Test04 {
    
        public static void main(String[] args) {
            Movie movie1 = new Movie("唐山大地震","冯小刚","灾难");
            Movie movie2 = new Movie("羞羞的铁拳","宋阳","喜剧");
            Movie movie3 = new Movie("集结号","冯小刚","历史");
            ArrayList<Movie> list = new ArrayList<Movie>();
            list.add(movie1);
            list.add(movie2);
            list.add(movie3);
            for (int i = 0; i < list.size(); i++) {
                if(list.get(i).getDirector().equals("冯小刚")){
                    System.out.println(list.get(i).getTitle()+"-"+list.get(i).getDirector()+"-"+list.get(i).getType());
                }
            }
        }
    
    }
  • 相关阅读:
    Cocos2d-x 3.0截屏功能集成
    游戏嵌入Webview网页
    Cocos2dx进阶学习之屏幕适配
    Android如何实现文件下载并自动安装apk包!!!
    LINQ Select变量定义 Expression<Func<TSource, TResult>>
    StringComparison枚举
    .net core DBFirst 生成Model表结构
    .net core反向工程Model生成 配置机密
    axios下载文件.net Core
    EFCore Database-first深入研究
  • 原文地址:https://www.cnblogs.com/YangGC/p/8511543.html
Copyright © 2011-2022 走看看