第五次作业·

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

             Driver.java的功能就是随机生成三个姓和三个名作为人的名字,再生成一个以及随机生成18-38以内的随机整数作为年龄;

    

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

    重构两个for循环的内容,一个用put(studentList)来输出随机产生的姓名和年龄;一个 generate_radom(studentList, random)来产生随机的姓、名和年龄;这样就方便其他人能读懂程序的功能室再干啥;使用的是myeclipse 中的refactor进行重构。除此之外,今天(5月26日),经过昨天老师的讲解,我再次对代码进行重构,把循环上限和年龄下限重构成常量。分别是:generate_threepepople和age_floor

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
        maxRandomNumber(studentList, random);
         
         
    //print out the students
    printStudent(studentList);
 
   }
 
    public static void printStudent(List<Student> studentList) {
        for (Student temp : studentList) {
            System.out.println(temp);
             
        }
    }
 
    public static void maxRandomNumber(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),写出观后感(内容是什么,说明了什么问题,有什么启示),提交到博客!

   1,明确自己对开发的目的,不能天马行空的想一切都是可以的。2,所以要求要符合实际,不能想当然就可以。3,对开发目的的实现要切合实际,从实际出发。

4、学习在项目中使用 jar 文件:

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



2)将四则运算程序的功能部分和界面部分分离,并将功能部分封装为jar文件(对java语言)或dll(对c语言);

原文地址:https://www.cnblogs.com/wujin111/p/4540830.html