首页 > 其他分享 >oop案例

oop案例

时间:2024-03-20 19:23:07浏览次数:33  
标签:String movies System 案例 oop println public out

oop案例1

电影类

package com.item.huang.demo01;

//电影类
public class Movie {
    //电影的属性
    private int id;
    private String name;
    private double price;
    private double score;
    private String director;
    private String actor;
    private String info;

    //无参构造
    public Movie() {
    }
    //有参构造(赋值)
    public Movie(int id, String name, double price, double score, String director, String actor, String info) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.score = score;
        this.director = director;
        this.actor = actor;
        this.info = info;
    }
    //封装属性
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    public String getDirector() {
        return director;
    }

    public void setDirector(String director) {
        this.director = director;
    }

    public String getActor() {
        return actor;
    }

    public void setActor(String actor) {
        this.actor = actor;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }
}

电影操作类

package com.item.huang.demo01;

//电影操作类
public class MovieOperator {
    private Movie[] movies;
    //有参构造(赋值)
    public MovieOperator(Movie[] movies) {
        this.movies = movies;
    }
    //1.展示电影全部信息
    public void printAllMovies(){
        System.out.println("全部电影信息如下:=============");
        for (int i = 0; i < movies.length; i++) {
            Movie m = movies[i];
            System.out.println("编号:"+m.getId());
            System.out.println("名称:"+m.getName());
            System.out.println("价格:"+m.getPrice());
        }
    }
    //2.根据电影的编号查询电影的详细信息并展示
    public void searchMovieById(int id){
        for (int i = 0; i < movies.length; i++) {
            Movie m = movies[i];
            if(id == m.getId()){
                System.out.println("该电影详情如下");
                System.out.println("编号:"+m.getId());
                System.out.println("名称:"+m.getName());
                System.out.println("价格:"+m.getPrice());
                System.out.println("得分:"+m.getScore());
                System.out.println("导演:"+m.getDirector());
                System.out.println("主演:"+m.getActor());
                System.out.println("其他信息:"+m.getInfo());
                return;//已经找到了电影信息
            }
        }
        System.out.println("没有电影信息!");
    }
}

测试类

package com.item.huang.demo01;


/*
*电影数据:
*       1,"水门桥",38.9,9.8,"徐克","吴京","12万人想看"
*       2,"出拳吧",39,7.8,"唐晓白","田雨","3.5万人想看"
*       3,"月球陨落",42,7.9,"罗兰","贝瑞","17.9万人想看"
*       4,"一点就到家",35,8.7,"许宏宇","刘昊然","10.8万人想看"
*
* 需求:
*       1.展示系统中的全部电影(每部电影展示:名称,价格)
*       2.允许用户根据电影编号(id)查询某部电影的详细信息
*
*       1.设计一个电影类
*       2.设计一个电影操作类
 */

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        //1.给电影赋值
        Movie[] movies = new Movie[4];
        movies[0] = new Movie(1,"水门桥",38.9,9.8,"徐克","吴京","12万人想看");
        movies[1] = new Movie(2,"出拳吧",39,7.8,"唐晓白","田雨","3.5万人想看");
        movies[2] = new Movie(3,"月球陨落",42,7.9,"罗兰","贝瑞","17.9万人想看");
        movies[3] = new Movie(4,"一点就到家",35,8.7,"许宏宇","刘昊然","10.8万人想看");
        //2.展示系统中的全部电影
        MovieOperator movieOperator = new MovieOperator(movies);
        movieOperator.printAllMovies();
        //3.用户根据电影编号(id)查询某部电影的详细信息
        System.out.println("===================================");
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("请输入想要查询的电影编号:");
            sc.hasNextInt();
            int id = sc.nextInt();
            if(id<1||id>4){
                System.out.println("输入的编号有误");
            }else {
                movieOperator.searchMovieById(id);
                break;//成功查询到电影
            }
        }
    }
}

标签:String,movies,System,案例,oop,println,public,out
From: https://www.cnblogs.com/qingandji/p/18085898

相关文章

  • Spring入门案例
    一、下载Spring5jar包官网地址:https://spring.io/版本目录:https://spring.io/projects/spring-framework#learn下载地址:https://repo.spring.io/ui/native/release/org/springframework/spring/二、新建java工程2.1新建项目2.2导入jar包必需的jar包2.2.1新建lib......
  • java基础案例
    java案例买飞机票packagecom.item.huang;//买飞机票publicclassTest01{publicstaticvoidmain(String[]args){doubleprice=calculate(1000,5,"经济舱");System.out.println(price);}//方法头需接收机票原价,当前月份,舱位类型......
  • 前端必学-40个精选案例实战-案例9:企业首页实战项目【PC端网页布局】
    项目首页.psd项目设计图头部导航条的制作资源:html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,......
  • dolphinscheduler调度任务执行hadoop命令报错(connot execute /opt/soft/hadoop/libexe
    问题描述在dolphinscheduler创建调度任务,任务里边命令为hadoopfs-mkdir-p/test/执行失败,报错信息如下:问题分析经排查该问题为dolphinscheduler配置的hadoop_home异常导致执行hadoop命令失败。问题解决配置dolphinscheduler服务config-env环境变量exportHADOOP_HOM......
  • 前端防止重复提交案例
    前端防止5秒内重复提交案例:varisBusy=0if(isBusy==1){errorMsg("5秒钟内不能重复提交!");returnfalse;}else{isBusy=1;setTimeout(functi......
  • 鸿蒙HarmonyOS实战-工具安装和Helloworld案例
    ......
  • [BX]和loop指令
    文章目录[BX]和loop指令1[bx]2Loop指令3在Debug中跟踪用loop指令实现的循环程序4Debug和汇编编译器Masm对指令的不同处理5loop和[bx]的联合应用6段前缀7一段安全的空间8段前缀的使用[BX]和loop指令1[bx]我们用[bx]表示一个内存单元,它的段地址默认在ds中,它......
  • 2.8 组装计算机案例分析
    #include<iostream>usingnamespacestd;//案例描述//电脑主要组成部件为CPU,显卡,内存条//将每个零件封装出抽象基类,并且提供不同的厂商生产不同的零件,例如Intel厂商提供cpu、nVidia厂商提供显卡、Samsung提供内存条//创建电脑类提供让电脑工作的函数,并且调用每个零件工作的......
  • Hadoop与Spark的x86和ARM混合集群部署【环境搭建篇】
    ​笔者在完成课程设计时,突然想到把大数据框架同时部署到PC端虚拟机以及ARM架构的Linux板上,这篇博客记录集群部署流程以及例程测试。部署架构如下图:若下文与架构图冲突,则以架构图为准。运行环境:PC方面,使用两台Ubuntu20.04LTSFocalFossa虚拟机ARM板子则使用香橙派5(R......
  • GEE高阶案例——利用eemont进行ee.Number对象类的运算(加减成熟运算公式)
    本教程的主要目的是利用eemont包对数字对象进行分析 代码!pipinstalleemont!pipinstallgeemapimportee,eemont,geemapimportgeemap.colormapsascm进行EE验证 验证并初始化地球引擎和地球地图。 Map=geemap.Map()让我们定义一些ee.Number对象作为近......