ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

每周总结第三周

2022-07-17 13:00:47  阅读:155  来源: 互联网

标签:总结 index 每周 int request dao 第三周 new response


本来应该是每周周六完成的,但是昨天忘记了,所以只能今天补上,

这一周我完成了数据结构小学期的第二阶段,

 

 

该系统的功能是以表单方式工作,进入主页面候可以看到当前一小时的车辆停泊情况。该系统有以下两个小功能

修改功能,用户可以选择添加当前一小时的新增的停泊车辆,并自动计算出本次渡船的情况。

查询功能,用户可以查询第n次渡船载车的信息。

从而实现用户的想法。在各项基本功能之下我们可以看到各种小的模块来满足用户的各种需求,达到快速方便的效果。

 

问题描述

渡口的每条渡船一次能装载6辆汽车过江,车辆分别为客车、鲜货车和普通客车3类,渡船管理规定:①同类汽车先到的先上船;②上传的优先级为:客车,鲜货车,普通货车;③每上3辆客车才允许上2辆鲜货车,然后再允许上1辆货车。若等待的客车不足3辆时,用鲜货车填补,

若等待的鲜货车不足2辆时,用货车填补,若没有货车等待时,按客车优先于鲜货车的原则填补;④当装满6辆后则自动开船;⑤1个小时为1个周期,若周期结束仍不满载则应人为控制开船。

设计要求:

(1)模拟各类车辆到大渡口的情况。

(2)模拟渡船开船的情况。

(3)提供文件保存各类模拟数据,并提供基于文件的多种查询。

 

需求分析

 

(1)汽车分为三个种类,且有不同的优先级

 

(2)三类汽车最多分别能一次性上3,2,1辆,一艘渡船最多可以载6辆

 

(3)同种类的汽车先到先上

 

(4)一个周期(1h)内,若不满载应人为控制开船。

 

存储结构

 

struct Information

 

{

 

 char kc[10];

 

 char xhc[10];

 

 char hc[10];

 

};

 

系统流程图

 

问题调试

1、问题一:读取到最新停泊车辆后无法更新

现象:文件内显存储的是一个方框

原因:没有将数据转化为合适的数据类型。

2、问题二:一次性保存多个文件

现象:文件夹中保存了六万多个相同的文件

原因:调用for循环,没有在适当时间将其停止。

3、问题三:无法查询到想要的结果

现象:文件夹中保存了六万多个相同的文件

原因:调用for循环,没有在适当时间将其停止。

4、问题四:当查询不存在的结果时出现问题

现象:直接报错

 

重要程序段1

public int[] look() {
    File file = new File("D:\\dan\\aa.txt");
    int line = 1;
    BufferedReader reader = null;
    String temp;
    int[] a = new int[3];
    {
        try {
            reader = new BufferedReader(new FileReader(file));
            while ((temp = reader.readLine()) != null) {
                a[line - 1] = Integer.parseInt(temp);
                line++;
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return a;
}

重要程序段2

public int[] add(int a,int b,int c){
    System.out.println(a+" "+b+" "+c);
    int[] x=new int[6];
    x[0]=0;
    x[1]=0;
    x[2]=0;
    x[3]=0;
    x[4]=0;
    x[5]=0;
    if(a+b+c<=6){
        x[0]=0;
        x[1]=0;
        x[2]=0;
        x[3]=a;
        x[4]=b;
        x[5]=c;
        a=0;
        b=0;
        c=0;
    }
    else {
        int index = 0;
        for (int i = 0; i < 6; i++) {
            if (a >= 3) {
                a -= 3;
                index += 3;
                x[3] += 3;
                if (index >= 6) {
                    int y = index - 6;
                    x[3] -= y;
                    a += y;
                    break;
                }
            } else {
                index += a;
                x[3] += a;
                a = 0;
                if (index >= 6) {
                    int y = index - 6;
                    x[3] -= y;
                    a += y;
                    break;
                }
            }
            if (b >= 2) {
                b -= 2;
                index += 2;
                x[4] += 2;
                if (index >= 6) {
                    int y = index - 6;
                    x[4] -= y;
                    a += y;
                    break;
                }
            } else {
                index += b;
                x[4] += b;
                b = 0;
                if (index >= 6) {
                    int y = index - 6;
                    x[4] -= y;
                    b += y;
                    break;
                }
            }
            if (c >= 1) {
                c -= 1;
                index += 1;
                x[5] += 1;
                if(index==6){
                    break;
                }
            }

        }
    }
    System.out.println(x[3]+" "+x[4]+" "+x[5]);
    x[0]=a;
    x[1]=b;
    x[2]=c;
    System.out.println(a+" "+b+" "+c);
    return x;
}

重要程序段3

public int change(int x[]){
    String name;
    File file =new File("D:\\dan\\aa.txt");
    try {
        FileWriter fileWriter =new FileWriter(file);
        fileWriter.write("");
        fileWriter.flush();
        fileWriter.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    FileOutputStream o = null;
    byte[] buff = new byte[]{};
    try{
        File file2 = new File("D:\\dan\\aa.txt");
        if(!file2.exists()){
            file2.createNewFile();
        }
        String b=x[0]+"\n"+x[1]+"\n"+x[2];
        buff=b.getBytes();
        o=new FileOutputStream(file2,true);
        o.write(buff);
        o.flush();
        o.close();
        for(int i=1;i>0;i++) {
            name="D:\\dan\\"+"第"+i+"次.txt";
            File file1 = new File(name);
            if (!file1.exists()) {
                file1.createNewFile();
                String a = x[3] + "\n" + x[4] + "\n" + x[5];
                buff = a.getBytes();
                o = new FileOutputStream(file1, true);
                o.write(buff);
                o.flush();
                o.close();
                break;
            }
            else{
                continue;
            }
        }
    }catch(Exception e){
        e.printStackTrace();
    }


    return 0;
}

重要程序段4

public int[] sel(int xxx) {
    String name="D:\\dan\\第"+xxx+"次.txt";
    File file = new File(name);
    int line = 1;
    BufferedReader reader = null;
    String temp;
    int[] a = new int[3];
    {
        try {
            reader = new BufferedReader(new FileReader(file));
            while ((temp = reader.readLine()) != null) {
                a[line - 1] = Integer.parseInt(temp);
                line++;
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return a;
}

重要程序段5

public class selServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");

        dao dao=new dao();
        int[] look = dao.look();
        aaa a=new aaa();
        a.ccc(look[0],look[1],look[2]);
        System.out.println(look[0]);
        List<aaa> aa = Arrays.asList(a);
        request.setAttribute("aa",aa);
        request.getRequestDispatcher("index.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}

重要程序段6

 

public class addServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        int kc = Integer.parseInt(request.getParameter("kc"));
        int xhc = Integer.parseInt(request.getParameter("xhc"));
        int hc = Integer.parseInt(request.getParameter("hc"));
        dao dao=new dao();
        int[] look = dao.look();
        int[] add = dao.add(look[0]+kc, look[1]+xhc, look[2]+hc);
        int change = dao.change(add);
        if(change==0){
            request.getRequestDispatcher("success.html").forward(request,response);
        }
        else{
            request.getRequestDispatcher("fail.html").forward(request,response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}


重要程序段7


@WebServlet("/sellServlet")
public class sellServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        int xxx = Integer.parseInt(request.getParameter("cs"));

        dao dao=new dao();
        int[] sel = dao.sel(xxx);
        aaa a=new aaa();
        a.ccc(sel[0],sel[1],sel[2]);
        List<aaa> aa = Arrays.asList(a);
        request.setAttribute("aa",aa);
        request.getRequestDispatcher("sel.jsp").forward(request,response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}

原因:没有应对错误的相应措施

 

对系统、对过程的总结体会

该系统整体过程并不是很难,唯一的难点在于如何按照要求进行存储。

所以也是比较容易完成的,刚开始的时候我本来就打算利用java文件进行开发,但是被我的同学一同忽悠,告诉我要求有界面,我就转战了javaweb,当我开发一半的时候忽然发现是每一个题的要求不同,并不是每一个题都要求有界面的,

当然,我也不后悔,做了一个有界面的也同时锻炼了自己javaweb与文件管理相结合的能力,中间有一些文件管理的内容是我之前的开发中运用比较少的,所以这一次也算是得到了充分的锻炼,最主要的还是在于

 对系统不足的描述并提出改进方案。

算法部分有待提升,数据结构在队列这一块学的就不是特别好,最拿手的是栈,所以就利用了循环,不过最多是六次循环,可以在这一方面进行改进。

还有就是可以把当前停放车辆录入一个车牌,从而达到区别每辆同种类车的一个情况。

 

 

标签:总结,index,每周,int,request,dao,第三周,new,response
来源: https://www.cnblogs.com/zhiqi2625/p/16486696.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有