欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java简写天然气储量管理系统

程序员文章站 2022-07-10 20:52:03
文章目录前言一、要求二、代码前言简单的实现了对数据的增添、删除、根据不同要求的查找一、要求中国天然气资源主要分布在几个大的气区,如塔里木盆地、四川盆地、柴达木盆地和陕甘宁盆地等;各个气区由多个气田组成,如塔里木盆地由克拉 2 气田、迪那 2气田、克深气田等组成,四川盆地由普光气田、龙王庙组气藏、涪陵页岩气田、元坝气田等组成,柴达木盆地由涩北气田等组成,陕甘宁盆地由苏里格气田、靖边气田、大牛地气田组成。请你设计一个简单的天然气储量管理系统,能够增删气田,能按气区浏览和查询气田数据,能分别按气藏类....


前言

简单的实现了对数据的增添、删除、根据不同要求的查找

一、要求

中国天然气资源主要分布在几个大的气区,如塔里木盆地、四川盆地、柴达木盆地和陕甘宁盆地等;各个气区由多个气田组成,如塔里木盆地由克拉 2 气田、迪那 2气田、克深气田等组成,四川盆地由普光气田、龙王庙组气藏、涪陵页岩气田、元坝气田等组成,柴达木盆地由涩北气田等组成,陕甘宁盆地由苏里格气田、靖边气田、大牛地气田组成。

请你设计一个简单的天然气储量管理系统,能够增删气田,能按气区浏览和查询气田数据,能分别按气藏类型或埋深类型汇总得到不同气区和中国的天然气储量

气田数据表格式如下所示:
气田名 气区 气藏类型 埋深类型 储量(亿方)
苏里格 陕甘宁盆地 常规气 中浅层气 5336.5

二、代码

代码如下(示例):

import java.util.Scanner;

class Data {
    String[] name = new String[100];
    String[] region = new String[100];
    String[] type = new String[100];
    String[] depth = new String[100];
    double[] reserve = new double[100];
}

public class DataMgr {
    Data data = new Data();

    public void initial() {
        data.name[0] = "普气";
        data.region[0] = "四川盆地";
        data.type[0] = "常规气";
        data.depth[0] = "浅层气";
        data.reserve[0] = 5000.00;

        data.name[1] = "龙王庙";
        data.region[1] = "四川盆地";
        data.type[1] = "煤层气";
        data.depth[1] = "中浅层气";
        data.reserve[1] = 4000.00;

        data.name[2] = "涪陵";
        data.region[2] = "四川盆地";
        data.type[2] = "页岩气";
        data.depth[2] = "中浅层气";
        data.reserve[2] = 4500.00;

        data.name[3] = "元坝";
        data.region[3] = "四川盆地";
        data.type[3] = "致密气";
        data.depth[3] = "深层气";
        data.reserve[3] = 6000.00;

        data.name[4] = "克拉2";
        data.region[4] = "塔里木盆地";
        data.type[4] = "常规气";
        data.depth[4] = "浅层气";
        data.reserve[4] = 5100.00;

        data.name[5] = "迪那2";
        data.region[5] = "塔里木盆地";
        data.type[5] = "常规气";
        data.depth[5] = "中浅层气";
        data.reserve[5] = 5200.00;

        data.name[6] = "克深";
        data.region[6] = "塔里木盆地";
        data.type[6] = "常规气";
        data.depth[6] = "深层气";
        data.reserve[6] = 5300.00;

        data.name[7] = "涩北";
        data.region[7] = "柴达木盆地";
        data.type[7] = "常规气";
        data.depth[7] = "浅层气";
        data.reserve[7] = 5400.00;

        data.name[8] = "苏里格";
        data.region[8] = "陕甘宁盆地";
        data.type[8] = "常规气";
        data.depth[8] = "中浅层气";
        data.reserve[8] = 5500.00;

        data.name[9] = "靖边";
        data.region[9] = "陕甘宁盆地";
        data.type[9] = "煤层气";
        data.depth[9] = "中浅层气";
        data.reserve[9] = 5600.00;

        data.name[10] = "大牛地";
        data.region[10] = "陕甘宁盆地";
        data.type[10] = "常规气";
        data.depth[10] = "浅层气";
        data.reserve[10] = 5700.00;
    }

    public void startMenu() {
        System.out.println("欢迎使用天然气管理系统");
        System.out.println("-----------------");
        System.out.println("0、增加");
        System.out.println("1、删除");
        System.out.println("2、按气区查看");
        System.out.println("3、按气藏类型汇总");
        System.out.println("4、按埋深类型汇总");
        System.out.println("5、总储量");
        System.out.println("6、退出");
        System.out.println("-----------------");
        System.out.print("请选择:");

        Scanner input = new Scanner(System.in);
        int choice = input.nextInt();

        if (choice == 0) {
            add();
            returnMain();
        } else if (choice == 1) {
            delete();
            returnMain();
        } else if (choice == 2) {
            search_by_region();
            returnMain();
        } else if (choice == 3) {
            search_by_type();
            returnMain();
        } else if (choice == 4) {
            search_by_depth();
            returnMain();
        } else if (choice == 5) {
            all_reserve();
            returnMain();
        } else if (choice == 6) {
            System.out.println("*******************");
            System.out.println("系统已退出,谢谢使用!");
            System.out.println("*******************");
        } else {
            System.out.println("输入错误!请重新输入!");
        }
    }

    public void add() {
        Scanner name = new Scanner(System.in);
        Scanner region = new Scanner(System.in);
        Scanner type = new Scanner(System.in);
        Scanner depth = new Scanner(System.in);
        Scanner reserve = new Scanner(System.in);
        System.out.println("--->气田数据(气田名;气区;气藏类型;埋深类型;储量)");
        System.out.print("请输入数据:");
        String name1 = name.next();
        String region1 = region.next();
        String type1 = type.next();
        String depth1 = depth.next();
        double reserve1 = Double.parseDouble(reserve.next());
        for (int i = 0; i < data.name.length; i++) {
            if (data.name[i] == null) {
                data.name[i] = name1;
                data.region[i] = region1;
                data.type[i] = type1;
                data.depth[i] = depth1;
                data.reserve[i] = reserve1;
                System.out.println("成功!");
                break;
            }
        }
    }

    public void delete() {
        System.out.println("请输入要删除的气田名称");
        Scanner input = new Scanner(System.in);
        String s = input.next();
        boolean check = false;
        for (int i = 0; data.name[i] != null; i++) {
            if (data.name[i].equals(s)) {
                check = true;
                for (int temp = i; temp < data.name.length - 1; temp++) {
                    data.name[temp] = data.name[temp + 1];
                    data.region[temp] = data.region[temp + 1];
                    data.type[temp] = data.type[temp + 1];
                    data.depth[temp] = data.depth[temp + 1];
                    data.reserve[temp] = data.reserve[temp + 1];
                }
                data.name[i] = null;
                data.region[i] = null;
                data.type[i] = null;
                data.depth[i] = null;
                data.reserve[i] = 0;
                System.out.println("成功");
                break;
            }

        }
        if (!check) {
            System.out.println("没有找到匹配信息!");
        }
        System.out.println("*******************");
    }


    public void search_by_region() {
        System.out.println("请输入气区名称");
        Scanner input = new Scanner(System.in);
        String s = input.next();
        System.out.println("气田名    气区    气藏类型    埋深类型    储量");
        for (int i = 0; data.region[i] != null; i++) {
            if (data.region[i].equals(s)) {
                System.out.println(data.name[i] + "    " + data.region[i] + "    " + data.type[i] + "    " + data.depth[i] + "    " + data.reserve[i]);
            }
        }
    }


    public void search_by_type() {
        System.out.println("--->查看信息");
        System.out.println("请输入气藏类型名称");
        Scanner input = new Scanner(System.in);
        String s = input.next();
        String[] new_region = new String[4];
        new_region[0] = "塔里木盆地";
        new_region[1] = "四川盆地";
        new_region[2] = "柴达木盆地";
        new_region[3] = "陕甘宁盆地";
        double[] sum = new double[4];
        for (int i = 0; data.type[i] != null; i++) {
            if (data.type[i].equals(s)) {
                for (int i1 = 0; i1 < new_region.length; i1++) {
                    if(new_region[i1].equals(data.region[i])){
                        sum[i1]=sum[i1]+data.reserve[i];
                    }
                }
            }
        }

        System.out.println("气区       储量");
        for (int i = 0; i < new_region.length; i++) {
            if (new_region[i] != null) {
                System.out.println(new_region[i] + "    " + sum[i]);
            }

        }
    }

    public void search_by_depth() {
        System.out.println("--->查看信息");
        System.out.println("请输入埋深类型名称");
        Scanner input = new Scanner(System.in);
        String s = input.next();
        String[] new_region = new String[4];
        new_region[0] = "塔里木盆地";
        new_region[1] = "四川盆地";
        new_region[2] = "柴达木盆地";
        new_region[3] = "陕甘宁盆地";
        double[] sum = new double[4];
        for (int i = 0; data.depth[i] != null; i++) {
            if (data.depth[i].equals(s)) {
                for (int i1 = 0; i1 < new_region.length; i1++) {
                    if(new_region[i1].equals(data.region[i])){
                        sum[i1]=sum[i1]+data.reserve[i];
                    }
                }
            }
        }

        System.out.println("气区       储量");
        for (int i = 0; i < new_region.length; i++) {
            if (new_region[i] != null) {
                System.out.println(new_region[i] + "    " + sum[i]);
            }

        }
    }


    public void all_reserve() {
        System.out.println("中国天然气储量:");
        double sum = 0.0;
        for (int i = 0; i < data.name.length; i++) {
            if (data.name[i] != null) {
                sum = sum + data.reserve[i];
            }
        }
        System.out.println(sum + "亿方");
    }


    public void returnMain() {
        Scanner input = new Scanner(System.in);
        System.out.print("输入0返回主菜单");
        if (input.nextInt() == 0) {
            startMenu();
        } else {
            System.out.println("输入错误,异常终止!");
        }
    }

}

class Start {
    public static void main(String[] args) {
        DataMgr start = new DataMgr();
        start.initial();
        start.startMenu();
    }
}

##.运行结果演示

如下(示例):
java简写天然气储量管理系统

java简写天然气储量管理系统
java简写天然气储量管理系统
java简写天然气储量管理系统

java简写天然气储量管理系统

本文地址:https://blog.csdn.net/x___z___/article/details/110951266

相关标签: java