1、请运行下面code,指出其功能;
(需附运行结果截图,并用简短文字描述其功能)
2、请将该code进行代码重构,使之模块化,并易于阅读和维护;
小提示: 请模仿课堂上的示例,可采用手动重构,或使用eclipse提供的重构工具进行,
3、观看视频The Expert (Short Comedy Sketch),写出观后感(内容是什么,说明了什么问题,有什么启示),提交到博客!
4、学习在项目中使用 jar 文件:
1)在下列code中导入jar文件“commons-lang3-3.3.2.jar”,并运行,将运行结果截图提交到博客:
1题:该系统主要是获取三个人的姓名和年龄
运行结果
2题:下面是重构的代码,重构后他们都自动生成了一个新的方法,在主结构中,使代码更易阅读。
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" }; private static void main(String[] args) { // create an empty list List<Student> studentList = new ArrayList(); // initialize random generator Random random = new Random(); // create random number of students xinxiStudent(studentList, random); // print out the students for (Student temp : studentList) { System.out.println(temp); } } public static void xinxiStudent(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)主要讲某公司要开发一个项目,对接这个项目的公司提出要求:画7根两两互相垂直的红线,有些用绿色墨水画,有些用透明墨水画。接这个项目的老板把任务交给项目经理,项目经理又把任务交给员工。员工接过任务后,讲“红线”就要红色墨水来画,用绿色墨水画不就是“绿线”了吗?因此,他认为用绿色墨水画红线是不可能的。
时间: 2024-10-24 10:20:26