zoukankan      html  css  js  c++  java
  • 第五次作业

    一.请运行下面code,指出其功能(需附运行结果截图,并用简短文字描述其功能)

    代码实现的功能:

    对程序中所给出的lastName,firstName中随机产生一个lastName和firstName就得到一个人的名字,并随机产生一个20以内的正整数,在加上18就是该名字的人的年龄。

    每运行一次程序就按照上述规则随机的产生,得到三个人的姓名和年龄。

    运行结果图:

    二.请将该code进行代码重构,使之模块化,并易于阅读和维护

       对Driver.java进行重构后的代码

     1 import java.util.ArrayList;
     2 import java.util.List;
     3 import java.util.Random;
     4 
     5 
     6 public class Driver {
     7 
     8     private static final int MAXNUMBER = 3;//MAXNUMBER就是产生的最大人数的个数
     9     private static String[] lastNames = {"Doe", "Smith", "Jones", "Adams", "Marshall", "Thompson", "Bradley", "Brown", "White", "Franklin", "Davis", "Cohn", "Clark"};
    10     private static String[] firstNames = {"Mary", "John", "Susan", "Michael", "David", "Lisa", "Wendy", "Diane", "Kelly", "Claire", "Elizabeth", "Mitchell", "Richard"};
    11 
    12     public static void main(String[] args) {
    13         
    14         // create an empty list
    15         List<Student> studentList = new ArrayList<Student>();
    16 
    17         // initialize random generator
    18         Random random = new Random();
    19         
    20         // create random number of students
    21         GetInformation(studentList, random);//该方法得到的是随机产生的人的信息(包括姓名和年龄)
    22         
    23         
    24     //print out the students
    25     PrintStudentInformation(studentList);//该方法用于输出学生的信息
    26 
    27    }
    28 
    29     private static void PrintStudentInformation(List<Student> studentList) {
    30         for (Student temp : studentList) {
    31             System.out.println(temp);
    32             
    33         }
    34     }
    35 
    36     private static void GetInformation(List<Student> studentList, Random random) {
    37         for (int i=0; i < MAXNUMBER; i++) {
    38 
    39             // get random first name
    40             String tempFirstName = firstNames[random.nextInt(firstNames.length)];
    41             
    42             // get random last name
    43             String tempLastName = lastNames[random.nextInt(lastNames.length)];
    44             
    45             // get random age
    46             int age = 18 + random.nextInt(20);
    47 
    48             // create student
    49             Student tempStudent = new Student(tempLastName, tempFirstName, age);
    50             
    51             // add them to the list
    52             studentList.add(tempStudent);
    53         }
    54     }
    55 
    56 }

    三.观看视频The Expert (Short Comedy Sketch),写出观后感(内容是什么,说明了什么问题,有什么启示),提交到博客!

          这个视频主要讲了一个工程师和一群完全什么技术都不懂的CEO,产品经理和设计师面前之间的对话。用户需要画7根红线,他们必须互相两两垂直,而且有一些用绿色墨水、有一些用透明墨水来画。开发人员认为用户的需求是不可能达到的,但是项目经理认为开发人员就是专家,专家就是要解决问题的。

           看完这个视频后,我觉得沟通是导致他们发生冲突的原因。客户对自己所需产品的特征没有和工程师解释清楚,导致工程师对此项目并不了解。其次工程师的上司是一个什么技术都不懂的CEO,认为工程师是自己雇来的员工,且是自己公司这方面的专家,就一定能解决好问题。这就是一个需求分析问题。一个项目能够很好地开发,需要开发人员对客户的需求进行深入的了解,而客户也需要清楚的给开发人员表达出自己的需求。

    四.学习在项目中使用 jar 文件

    1)在下列code中导入jar文件“commons-lang3-3.3.2.jar”,并运行,将运行结果截图提交到博客:

    import org.apache.commons.lang3.time.StopWatch;
    
    public class Driver {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            System.out.println("Running...");
    
            StopWatch myStopWatch = new StopWatch();
    
            myStopWatch.start();
    
            performLengthyProcess();
    
            myStopWatch.stop();
    
            System.out.println("Time is:" + myStopWatch.getTime() + " millis");
    
            System.out.println("Finished...");
    
        }
    
        private static void performLengthyProcess() {
            try {
                Thread.sleep(3000); // 3 second delay
    
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    
    }

    运行结果图:

  • 相关阅读:
    冒泡排序
    【代码审计】appcms 文件包含漏洞
    【知识学习】PHP实现批量替换字典后缀
    【代码学习】PYTHON 列表循环遍历及列表常见操作
    【代码学习】PYTHON字符串的常见操作
    【知识学习】Sublime Text 快捷键精华版
    【代码审计】变量覆盖漏洞详解
    【渗透测试】Msf提权步骤
    【代码审计】VAuditDemo 前台搜索功能反射型XSS
    【代码审计】VAuditDemo 前台搜索注入
  • 原文地址:https://www.cnblogs.com/TaurusChenLi/p/4534147.html
Copyright © 2011-2022 走看看