软件工程第五次作业
1、请运行下面code,指出其功能;
(需附运行结果截图,并用简短文字描述其功能)
(功能:随机产生三个姓名 和数字)
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(); 15 16 // initialize random generator 17 Random random = new Random(); 18 19 // create random number of students 20 for (int i=0; i < 3; i++) { 21 22 studentsmessage(studentList, random); 23 } 24 25 26 //print out the students 27 for (Student temp : studentList) { 28 System.out.println(temp); 29 30 } 31 32 } 33 34 public static void studentsmessage(List<Student> studentList, Random random) { 35 // get random first name 36 String tempFirstName = firstNames[random.nextInt(firstNames.length)]; 37 38 // get random last name 39 String tempLastName = lastNames[random.nextInt(lastNames.length)]; 40 41 // get random age 42 int age = 18 + random.nextInt(20); 43 44 // create student 45 Student tempStudent = new Student(tempLastName, tempFirstName, age); 46 47 // add them to the list 48 studentList.add(tempStudent); 49 } 50 51 }
3、观看视频The Expert (Short Comedy Sketch),写出观后感(内容是什么,说明了什么问题,有什么启示),提交到博客!
内容:这个视频主要讲的是一个公司要做一个新产品,对新产品的要求是:画七根红线,一些用绿色墨水画,一些用透明墨水画,这七根线要两两垂直。在整个团队的交流中,开发人员认为用户的需求不可能达到的。但是项目经理认为开发人员就是专家!所以用户的任何需求都是可以完成的。
启示:想象与现实是有差距的。
4、学习在项目中使用 jar 文件:
1)在下列code中导入jar文件“commons-lang3-3.3.2.jar”,并运行,将运行结果截图提交到博客: