第五次作业

1.请运行下面code,指出其功能;

(需附运行结果截图,并用简短文字描述其功能)

功能:随机生成三个人的姓、名和年龄。年龄的值在18-38之间。

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

import java.util.ArrayList;
import java.util.List;
import java.util.Random;


public class Driver {

    private static String[] lastNames = {"Doe", "Smith", "Jones", "Adams", "Marshall", "Thompson", "Bradley", "Brown", "White", "Franklin", "Davis", "Cohn", "Clark"};
    private static String[] firstNames = {"Mary", "John", "Susan", "Michael", "David", "Lisa", "Wendy", "Diane", "Kelly", "Claire", "Elizabeth", "Mitchell", "Richard"};

    public static void main(String[] args) {
        
        // create an empty list
        List<Student> studentList = new ArrayList<Student>();

        // initialize random generator
        Random random = new Random();
        
        // create random number of students
        mt(studentList, random);
        
        
    //print out the students
    maotao(studentList);

   }

    public static void maotao(List<Student> studentList) {
        for (Student temp : studentList) {
            System.out.println(temp);
            
        }
    }

    public static void mt(List<Student> studentList, Random random) {
        for (int i=0; i < 3; i++) {

            // get random first name
            String tempFirstName = firstNames[random.nextInt(firstNames.length)];
            
            // get random last name
            String tempLastName = lastNames[random.nextInt(lastNames.length)];
            
            // get random age
            int age = 18 + random.nextInt(20);

            // create student
            Student tempStudent = new Student(tempLastName, tempFirstName, age);
            
            // add them to the list
            studentList.add(tempStudent);
        }
    }

}

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

内容:公司要做一个新产品,要求画七根红线,一部分用绿色,一部分用透明,尔而且七根线两两垂直。在团队交流中,都认为不能达到客户的需求。项目经理认为开发人员是专家,所以公司能满足客户任何的要求。

做事应该根据实际情况来做。

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

原文地址:https://www.cnblogs.com/luowenhao/p/4542725.html