Java开学考试

石家庄铁道大学2023年秋季

  2022 课堂测试试卷(一)15分)

课程名称: JAVA语言程序设计  任课教师 王建民        考试时间: 180 分钟  

 

一、考试要求:

1、按照测试内容要求完成程序的设计与编程;

2、建立学号姓名文件夹,如:“信2205-120223921赵福奇”,将源程序文件、保存在文件夹中,压缩成rar文件提交。

3、以班级为单位上交最终考试结果。

4、需要在程序开始的注释中注明班级、学号、姓名

、系统背景

某机械有限公司为了公司进一步的发展,需要实现企业数字化管理,新引进一套企业信息管理系统(ERP由于该产品缺乏入库功能,特委托石家庄铁道大学信息科学与技术学院前进22软件有限公司开发仓库管理功能。

二、 数据结构要求:(5分)

1定义WarehouseInformation类,其中包括个私有变量(itemnoitemnamesuppliername,warehousingtime,shipmenttimewarehousenumber,warehouseplace,itemnumber,outnumber)。

各成员的含义如下:

变量itemno 为字符串类型 String表示商品编号(有8 位数字组成)。

变量itemname 为字符串类型 String表示商品名称

变量suppliernameString 类型,表示供货商名称。

变量warehousingtimeString 类型,表示入库时间,长度八位例如:20230904

变量shipmenttimeString类型,表示出库时间,长度八位例如:20230904,如果该商品未出库,则出库时间为空,如果该商品已出库,则要求出库时间必须晚于入库时间。

变量warehousenumberString类型,表示仓库编号。长度三位。

变量warehouseplaceString类型,表示存放商品的具体位置,长度八位数字XXXXYYZZ其中XXXX表示货架号,YY表示货架的层号,ZZ表示存放在该货架该层的商品顺序号。

变量itemnumber为整型,表示入库商品的数量。

变量outnumber为整型,表示出库商品的数量。

 

对每个变量定义 get()(读取变量信息)和 set()(设置变量信息)的方法。

2赋初值方法包括个参数,用于为变量sitemnumberitemnamesuppliername,warehousingtime,shipmenttimewarehousenumber,warehouseplace,itemnumber,outnumber)赋值。

 

package com.lty;

import java.util.Scanner;

public class Main {
    Scanner sc=new Scanner(System.in);

    public static  void  show(){
        System.out.println("***********************************************************");
        System.out.println("石家庄铁道大学前进22软件开发有限公司");
        System.out.println("仓库管理系统2022版");
        System.out.println("***********************************************************");
        System.out.println("1、商品入库管理");
        System.out.println("2、商品信息修改");
        System.out.println("3、商品出库管理");
        System.out.println("4、仓库盘点管理");
        System.out.println("**********************************************************");
    }
    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);
        WarehouseManagement t=new WarehouseManagement();
        t=new WarehouseManagement();
        while(true){
            show();
            int n=sc.nextInt();
            if(n==1){
                t.input();//入库
            }else if(n==2){
                t.change();//改变
            }else if(n==3){
                t.output();//出库
            }else if(n==4){
                t.endpower();break;//盘点并结束
            }else{
                System.out.println("输入的序号错误,请重新输入!");
            }
        }
    }
}
/*-----------------------------------------信息类--------------*/
class WarehouseInformation{
    private String itemno,itemname,suppliername,warehousingtime,shipmenttime,warehousenumber,warehouseplace;
    private int itemnumber,outnumber;
    public  int cnt=0;
    public WarehouseInformation(){
        itemno="";
        itemname="";
        suppliername="";
        shipmenttime="";
        warehousenumber="";
        warehouseplace="";
        itemnumber=0;outnumber=0;
    }
    public String getItemname(){
        return itemname;
    }

    public void setItemname(String itemname) {
        this.itemname = itemname;
    }

    public String getWarehousingtime() {
        return warehousingtime;
    }

    public void setWarehousingtime(String warehousingtime) {
        this.warehousingtime = warehousingtime;
    }

    public int getItemnumber() {
        return itemnumber;
    }
    public void setItemnumber(int a){
        this.itemnumber=a;
    }

    public void setOutnumber(int outnumber) {
        this.outnumber = outnumber;
    }

    public int getOutnumber() {
        return outnumber;
    }

    public String getItemno() {
        return itemno;
    }

    public void setItemno(String itemno) {
        this.itemno = itemno;
    }

    public String getShipmenttime() {
        return shipmenttime;
    }

    public void setShipmenttime(String shipmenttime) {
        this.shipmenttime = shipmenttime;
    }

    public String getSuppliername() {
        return suppliername;
    }

    public void setSuppliername(String suppliername) {
        this.suppliername = suppliername;
    }

    public String getWarehousenumber() {
        return warehousenumber;
    }

    public void setWarehousenumber(String warehousenumber) {
        this.warehousenumber = warehousenumber;
    }

    public String getWarehouseplace() {
        return warehouseplace;
    }

    public void setWarehouseplace(String warehouseplace) {
        this.warehouseplace = warehouseplace;
    }
}

/*-------------------------------------执行类--------------------*/
class WarehouseManagement extends WarehouseInformation{
    WarehouseInformation[] ans=new WarehouseInformation[5];
    public int cnt=0;
    Scanner sc=new Scanner(System.in);
    public void input(){
        while(true) {
            System.out.println("***********************************************************");
            System.out.println("石家庄铁道大学前进22软件开发有限公司");
            System.out.println("仓库管理系统2022版");
            System.out.println("***********************************************************");
            System.out.println("商品编号:");
            String k;
            WarehouseInformation s = new WarehouseInformation();
            k = sc.next();
            s.setItemno(k);
            if (s.getItemno().length() != 8) {
                System.out.println("输入错误,请重新输入(八位):");
                k = sc.next();s.setItemno(k);
            }
            System.out.println("商品名称:");
            k = sc.next();
            s.setItemname(k);
            System.out.println("供货商信息:");
            k = sc.next();
            s.setSuppliername(k);
            System.out.println("入库时间:");
            k = sc.next();
            s.setWarehousingtime(k);
            if (s.getWarehousingtime().length() != 8) {
                System.out.println("输入错误,请重新输入(八位):");
                k = sc.next();
                s.setWarehousingtime(k);
            }
            System.out.println("仓库编号:");
            k = sc.next();
            s.setWarehousenumber(k);
            if (s.getWarehousenumber().length() != 3) {
                System.out.println("输入错误,请重新输入(八位):");
                k = sc.next();
                s.setWarehousenumber(k);
            }
            System.out.println("存放位置信息:");
            k = sc.next();
            s.setWarehouseplace(k);
            if (s.getWarehouseplace().length() != 8) {
                System.out.println("输入错误,请重新输入(八位):");
                k = sc.next();
                s.setWarehouseplace(k);
            }
            System.out.println("入库商品数量:");
            int y=sc.nextInt();
            s.setItemnumber(y+s.getItemnumber());
            System.out.println("**********************************************************");

            System.out.println("***********************************************************");
            System.out.println("石家庄铁道大学前进22软件开发有限公司");
            System.out.println("仓库管理系统2022版");
            System.out.println("***********************************************************");
            System.out.println("商品编号:");
            System.out.println(s.getItemno());
            System.out.println("商品名称:");
            System.out.println(s.getItemname());
            System.out.println("供货商信息:");
            System.out.println(s.getSuppliername());
            System.out.println("入库时间:");
            System.out.println(s.getWarehousingtime());
            System.out.println("仓库编号:");
            System.out.println(s.getWarehousenumber());
            System.out.println("存放位置信息:");
            System.out.println(s.getWarehouseplace());
            System.out.println("入库商品数量:");
            System.out.println(s.getItemnumber());
            System.out.println("该商品入库操作已完成,是否提交(Y/N)");
            System.out.println("**********************************************************");
            String c = sc.next();
            if (c.equals("Y")) {
                ans[cnt++] = s;
                break;
            } else {
                continue;
            }
        }
    }
    public void output(){
        while(true) {
            int i;WarehouseInformation s=ans[0];
            System.out.println("***********************************************************");
            System.out.println("石家庄铁道大学前进22软件开发有限公司");
            System.out.println("仓库管理系统2022版");
            System.out.println("***********************************************************");
            System.out.println("请输入商品编号:");
            String k;
            k = sc.next();
            System.out.println("***********************************************************");
            boolean f=false;
            for(i=0;i<cnt;i++){
                if(k.equals(ans[i].getItemname())){
                    System.out.println("***********************************************************");
                    System.out.println("石家庄铁道大学前进22软件开发有限公司");
                    System.out.println("仓库管理系统2022版");
                    s=ans[i];
                    System.out.println("***********************************************************");
                    System.out.println("1商品编号:");
                    System.out.println(s.getItemno());
                    System.out.println("2商品名称:");
                    System.out.println(s.getItemname());
                    System.out.println("3供货商信息:");
                    System.out.println(s.getSuppliername());
                    System.out.println("4入库时间:");
                    System.out.println(s.getWarehousingtime());
                    System.out.println("5仓库编号:");
                    System.out.println(s.getWarehousenumber());
                    System.out.println("6存放位置信息:");
                    System.out.println(s.getWarehouseplace());
                    System.out.println("7入库商品数量:");
                    System.out.println(s.getItemnumber());
                    System.out.println("出库时间:");
                    String o=sc.next();
                    System.out.println("出库数量:");
                    int n=sc.nextInt();
                    System.out.println("**********************************************************");
                    s.setShipmenttime(o);
                    s.setOutnumber(n+s.getOutnumber());
                    f=true;break;
                }
                if(i==cnt-1&&!f){
                    System.out.println("编号错误");
                    f=true;break;
                }
            }
            if(!f)
                continue;
            else{
                System.out.println("选择“Y”保存结果,返回系统主界面。选择“N”, 返回当前界面。");
                k=sc.next();
                if(k.equals("Y")){
                    ans[i]=s;break;
                }else{
                    continue;
                }
            }
        }
    }
    public void change(){
        while(true) {
            System.out.println("***********************************************************");
            System.out.println("石家庄铁道大学前进22软件开发有限公司");
            System.out.println("仓库管理系统2022版");
            System.out.println("***********************************************************");
            System.out.println("请输入商品编号:");
            String k;
            k = sc.next();
            System.out.println("***********************************************************");
            boolean f=false;
            for(int i=0;i<cnt;i++){
                if(k.equals(ans[i].getItemname())){
                    System.out.println("***********************************************************");
                    System.out.println("石家庄铁道大学前进22软件开发有限公司");
                    System.out.println("仓库管理系统2022版");
                    WarehouseInformation s=ans[i];
                    System.out.println("***********************************************************");
                    System.out.println("1商品编号:");
                    System.out.println(s.getItemno());
                    System.out.println("2商品名称:");
                    System.out.println(s.getItemname());
                    System.out.println("3供货商信息:");
                    System.out.println(s.getSuppliername());
                    System.out.println("4入库时间:");
                    System.out.println(s.getWarehousingtime());
                    System.out.println("5仓库编号:");
                    System.out.println(s.getWarehousenumber());
                    System.out.println("6存放位置信息:");
                    System.out.println(s.getWarehouseplace());
                    System.out.println("7入库商品数量:");
                    System.out.println(s.getItemnumber());
                    System.out.println("请选择需要修改的信息编号(1-7):");
                    int n=sc.nextInt();
                    System.out.println("**********************************************************");
                    if(n<1||n>7){
                        System.out.println("数据不存在!");
                        f=true;break;
                    }else{
                        System.out.println("***********************************************************");
                        System.out.println("石家庄铁道大学前进22软件开发有限公司");
                        System.out.println("仓库管理系统2022版");
                        System.out.println("***********************************************************");
                        System.out.println("1商品编号:");
                        System.out.println(s.getItemno());
                        System.out.println("2商品名称:");
                        System.out.println(s.getItemname());
                        System.out.println("3供货商信息:");
                        System.out.println(s.getSuppliername());
                        System.out.println("4入库时间:");
                        System.out.println(s.getWarehousingtime());
                        System.out.println("5仓库编号:");
                        System.out.println(s.getWarehousenumber());
                        System.out.println("6存放位置信息:");
                        System.out.println(s.getWarehouseplace());
                        System.out.println("7入库商品数量:");
                        System.out.println(s.getItemnumber());
                        System.out.println("请选择需要修改的信息编号(1-7):");
                        System.out.println(n);
                        System.out.println("请输入修改后的商品名称:");
                        if(n==1){String id=sc.next();
                            ans[i].setItemno(id);
                        }else if(n==2){String id=sc.next();
                            ans[i].setItemname(id);
                        }else if(n==3){String id=sc.next();
                            ans[i].setSuppliername(id);
                        }else if(n==4){String id=sc.next();
                            ans[i].setWarehousingtime(id);
                        }else if(n==5){String id=sc.next();
                            ans[i].setWarehousenumber(id);
                        }else if(n==6){String id=sc.next();
                            ans[i].setWarehouseplace(id);
                        }else{int id=sc.nextInt();
                            ans[i].setItemnumber(id);
                        }
                        System.out.println("***********************************************************");
                        break;
                    }
                }
            }
            if(f)
                continue;
            else
                break;
        }
    }
    public void endpower(){
        System.out.println("***********************************************************");
        System.out.println("石家庄铁道大学前进22软件开发有限公司");
        System.out.println("仓库管理系统2022版");
        System.out.println("***********************************************************");
        for(int i=0;i<cnt;i++){
            System.out.printf("%d   商品编号:%s, 商品名称:%s,库存数量:%d\n",i+1,ans[i].getItemno(),ans[i].getItemname(),ans[i].getItemnumber()-ans[i].getOutnumber());
        }
        System.out.println("………………………………………………….");
        System.out.println("**********************************************************");
    }
}

 

posted on 2023-09-11 22:27  临江柔  阅读(55)  评论(0)    收藏  举报