1、请运行下面code,指出其功能;
随机产生三个人的名字和姓,还可以随机产生18--38之间的数作为他们的年龄。
2、请将该code进行代码重构,使之模块化,并易于阅读和维护;
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 String[] lastNames = {"Doe", "Smith", "Jones", "Adams", "Marshall", "Thompson", "Bradley", "Brown", "White", "Franklin", "Davis", "Cohn", "Clark"}; 9 private static String[] firstNames = {"Mary", "John", "Susan", "Michael", "David", "Lisa", "Wendy", "Diane", "Kelly", "Claire", "Elizabeth", "Mitchell", "Richard"}; 10 11 public static void main(String[] args) { 12 13 // create an empty list 14 List<Student> studentList = new ArrayList<Student>(); 15 16 // initialize random generator 17 Random random = new Random(); 18 19 // create random number of students 20 loop(studentList, random); 21 22 23 //print out the students 24 for (Student temp : studentList) { 25 printDetails(temp); 26 27 } 28 29 } 30 31 public static void loop(List<Student> studentList, Random random) { 32 for (int i=0; i < 3; i++) { 33 34 // get random first name 35 String tempFirstName = firstNames[random.nextInt(firstNames.length)]; 36 37 // get random last name 38 String tempLastName = lastNames[random.nextInt(lastNames.length)]; 39 40 // get random age 41 int age = 18 + random.nextInt(20); 42 43 // create student 44 Student tempStudent = new Student(tempLastName, tempFirstName, age); 45 46 // add them to the list 47 studentList.add(tempStudent); 48 } 49 } 50 51 public static void printDetails(Student temp) { 52 System.out.println(temp); 53 } 54 }
3、观看视频The Expert (Short Comedy Sketch),写出观后感(内容是什么,说明了什么问题,有什么启示),提交到博客!
内容:一群领导总是把专家当神看待,总觉他们是专家,所以就没有什么是他们解决不了的问题。
纯在的问题:知识领域的不同,导致个人看法的不同,使他们的沟通纯在许多问题,最终无法完成客户的需求。
启示:在和客户交流的过程中一定要把我们需要了解的客户需求进行刨根问底,而最终无法完成的客户需求我们应该果断拒绝,而不是各自浪费彼此的时间。
4、学习在项目中使用 jar 文件:
1)在下列code中导入jar文件“commons-lang3-3.3.2.jar”,并运行,将运行结果截图提交到博客: