哈工大软件构造Lab1(2022)
阅读原文时间:2022年05月11日阅读:1

目录

一、实验目标概述

二、实验环境配置

1、安装编写java程序的IDE——IntelliJ IDEA

2、安装Git

3、安装Junit

4、GitHub Lab1仓库的URL地址

三、实验过程

1、Magic Squares

(1)isLegalMagicSquare()

(2)generateMagicSquare()

(3)源代码

2、Turtle Graphics

(1)Problem 1:Clone and import

(2)Problem 3:Turtle graphics and drawSquare

(3)Problem 5:Drawing polygons

(4)Problem 6:Calculating Bearings

(5)Problem 7:Convex Hulls

(6)Problem 8:Personal Art

(7)Submitting

3、Social Network

(1)设计/实现FriendshipGraph类

(2)设计实现Person类

(3)设计/实现​​​​​​客户端代码main()

(4)设计/实现测试用例

四、实验收获

1、经验/教训

2、感想


一、实验目标概述

本次实验通过求解三个问题,训练基本 Java 编程技能,能够利用 Java OO 开发基本的功能模块,能够阅读理解已有代码框架并根据功能需求补全代码,能够为所开发的代码编写基本的测试程序并完成测试,初步保证所开发代码的正确性。另一方面,利用 Git 作为代码配置管理的工具,学会 Git 的基本使用方法。

二、实验环境配置

由于2021夏季小学期选择了田英鑫老师的JavaEE课程,所以已经下载并配置好了编写Java程序的IDE:IntelliJ IDEA

打开Git官网准备安装时发现,自己原来在大一时便已安装并配置好了Git工具,因此不需要再重复安装配置。

已于2021年11月14日安装完成Git。

打开IDEA的扩展市场:

在纠结下载安装哪一款插件时咨询了同学,经同学告知,下载了如下插件并安装在IDEA上:

https://github.com/ComputerScienceHIT/HIT-Lab1-120L022408

三、实验过程

本题与Magic Square有关,Magic Square,即幻方,查阅百科后了解到,幻方是一种将数字安排在正方形格子中,使每行、列和对角线上的数字和都相等的方法。题目1要求编写一个Java程序(MagicSquare)先来检查给定txt文档中所记录点五个矩阵的行/列/对角线值,然后分别判断它们是否是一个幻方。题目2要求对给出的产生幻方的代码(generateMagicSquare)进行改进扩展后加入MagicSquare类中进行测试。

(1)isLegalMagicSquare()

a、函数分析

本题要求编写一个函数isLegalMagicSquare()判断一个txt文件中保存的矩阵是否为符合幻方要求的矩阵。输入参数为txt文件的文件路径,函数返回一个boolean值,若符合要求返回true,否则返回false。

判断幻方的合法性:

根据幻方的定义,首先需要判断幻方必须是行数与列数相等的矩阵,假设幻方为N * N的矩阵,那么幻方的元素值都是自然数集上从1到N * N的一个排列,不能为负数,不能为浮点数,两两元素值也不能相同。最后确定行列和、对角线和之间是否全部相等,若是,则为幻方,函数返回true。

b、实现思路

首先根据函数参数传入的文件路径new一个file对象,使用FileInputStream流读取文件的内容,并保存在一个String类型的content字符串中。

将文件内容读取到String后开始对文件内容做处理,使用split("\n")方法检测出文本中的换行标记,并以此分割出矩阵的每一行,并保存进一个字符串数组String line[]中,此时可调用length方法计算得出矩阵的行数row_num。再对矩阵的每一行进行处理,使用split("\t")方法检测出每一行元素之间的分隔标记,并以此将其划分为一个个数字字符串,保存在String[] line_cut中,并使用Integer.valueOf(String ).intValue()方法,得到字符串转换为的数字num,循环保存至幻方中。至此,对文件的读入及初始数据的处理完成。

在处理文本数据的过程中已判断了行数与列数是否相等,故之后只需判断一个行列数相等的矩阵元素是否满足要求。由于在之前的try-catch语句中已将非整形数据的报错抛出,故不需要考虑int型以外的其他数据格式。设置一个boolean[]数组test来判断元素的值是否已经出现过,初始化将其全设置为false,每读入一个元素,若不小于0且未出现过,则将其值所对应的boolean[]数组元素的值置为true。

最后判断行列和、对角线和是否全部相等,若是则返回true,否则返回false。

(2)generateMagicSquare()

a、该函数的程序流程图

b、实现思路

分析该函数的内容,给定一个参数n作为幻方的行列数,将初始位置置为(0, n / 2), 之后依次对1 ~ n * n赋值给一个位置,1赋值给初始位置,然后计算下一个位置为当前位置的右上位置。对于边界情况:若当前行是第一行,则下一行取最后一行;若当前列是最右边的那列,则下一列取最左边的那列。当i能被n整除时,则将当前位置正下方的第一个位置赋值为i + 1,然后继续循环赋值。当循环n的平方次后,即对整个矩阵赋完了值,且满足每行每列以及两条对角线之和均相同的约束。

c、对该函数进行扩展

I、将产生的magic square写入文件夹\src\P1\txt\6.txt中

使用FileWriter和BufferedWriter类写入magic数组所存储的矩阵中保存的内容。代码如下所示:

II、当输入的参数n不合法时,输出提示和false退出

在main()函数中给generateMagicSquare()传递参数前进行判断,用String str保存从键盘接收到的字符串的值,并用Integer.valueOf(str)将其转换为数值保存到num中,这一步中若catch到NumberFormatException错误,则说明参数num不为整形,打印错误信息并提示重新输入。

再在generateMagicSquare()函数中对参数n做判断:若n为偶数,则打印错误信息并返回false;若n为负数,则catch到NegativeArraySizeException错误,同样打印错误信息并返回false。

(3)源代码

package P1;

import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

public class MagicSquare
{
    static final int N = 200;
    public static int[][] square = new int[N][N];
    public static boolean[] test = new boolean[N * N + 1];

    public static boolean isLegalMagicSquare (String fileName)
    {
        File file = new File(fileName);
        String content = null;
        Long file_len = file.length();
        byte[] file_content = new byte[file_len.intValue()];
        int col_num = 0, row_num = 0;
        Arrays.fill(test, false);
        try {
            FileInputStream file_In = new FileInputStream(file);
            file_In.read(file_content);
            file_In.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            content = new String(file_content, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            System.err.println("We don't support UTF-8\t");
            e.printStackTrace();
        }

        String line[] = content.split("\n");
        row_num = line.length;
        col_num = row_num;
        int sum_Row[] = new int[row_num];
        int sum_Col[] = new int[col_num];
        int sum_Dia[] = new int[2];

        for (int i = 0; i < row_num; i++)
        {
            String[] line_cut = line[i].split("\t");
            if(line_cut.length != row_num)
            {
                System.out.print("行列数不相等 或者未使用'\\t'分隔\t");
                return false;
            }
            for (int j = 0; j < row_num; j++)
            {
                try {
                    int num = Integer.valueOf(line_cut[j]).intValue();
                    square[i][j] = num;
                } catch (NumberFormatException e) {
                    System.out.print("存在非法输入\t");
                    return false;
                }
                if (square[i][j] <= 0 || test[ square[i][j] ] == true)
                {
                    System.out.print("存在负数或至少存在两数相等\t\t");
                    return false;
                }
                else
                {
                    test[ square[i][j] ] = true;
                    sum_Row[i] += square[i][j];
                    sum_Col[j] += square[i][j];
                    if (i == j)
                    {
                        sum_Dia[0] += square[i][j];
                    }
                    if (i + j + 1 == col_num)
                    {
                        sum_Dia[1] += square[i][j];
                    }
                }
            }
        }
        if(sum_Dia[0] != sum_Dia[1])
        {
            System.out.print("两条对角线和不相等\t");
        }
        int Sum = sum_Dia[0];
        for(int i = 0; i < row_num; i++)
        {
            if (sum_Row[i] != Sum || sum_Col[i] !=Sum)
            {
                System.out.print("行列和与对角线和不相等\t");
                return false;
            }
        }
        return true;
    }

    public static boolean generateMagicSquare(int n)
    {
        try {
            if (n % 2 == 0)
            {
                System.out.println("输入为偶数\t");
                return false;
            }
            else
            {
                int magic[][] = new int [n][n];
                int row = 0, col = n / 2, i, j, square = n * n;
                for (i = 1; i <= square; i++)
                {
                    try {
                        magic[row][col] = i; //递增地给当前位置赋值
                    } catch (ArrayIndexOutOfBoundsException e) {
                        System.out.println("输入错误\t");
                        return false;
                    }
                    if (i % n == 0)
                    {
                        row++; //当i恰赋完n的倍数个值时,下一位置取当前位置的正下方第一个位置
                    }
                    else
                    {
                        if (row == 0)
                        {
                            row = n - 1; //如果元素位置来到了第一行,则从最后一行开始
                        }
                        else
                        {
                            row--; //正常情况下行数-1
                        }
                        if (col == (n - 1))
                        {
                            col = 0; //如果元素位置来到了最后一列,则从第一列开始
                        }
                        else
                        {
                            col++; //正常情况下列数+1
                        }
                    }
                }
                //输出矩阵元素
                for (i = 0; i < n; i++)
                {
                    for (j = 0; j < n; j++)
                    {
                        System.out.print(magic[i][j] + "\t");
                    }
                    System.out.println();
                }
                //写入文件6.txt
                File writeOut = new File("src/P1/txt/6.txt");
                try {
                    writeOut.createNewFile();
                    FileWriter FWriter = new FileWriter(writeOut);
                    BufferedWriter BfWriter = new BufferedWriter(FWriter);
                    for (i = 0; i < n; i++)
                    {
                        for (j = 0; j < n; j++)
                        {
                            BfWriter.write(magic[i][j] + "\t");
                        }
                        BfWriter.write("\n");
                    }
                    BfWriter.flush();
                    BfWriter.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }

                return true;
            }
        } catch (NegativeArraySizeException e) {
            System.out.println("输入为负数\t");
            return false;
        }
    }

    public static void main(String[] args)
    {
        System.out.println("检测以下五个txt中是否为幻方,若是则返回true,不是则打印错误原因并返回false:");
        for (char i = '1'; i <= '5'; i++)
        {
            System.out.print(i + ".txt\t");
            System.out.println(isLegalMagicSquare("src/P1/txt/" + i + ".txt"));
        }

        String str;
        Scanner scan = new Scanner(System.in);

        while (true)
        {
            System.out.println("请输入奇数的幻方宽度或输入'stop'以结束程序:");
            str = scan.nextLine();
            if(str.equals("stop"))
            {
                System.out.println("程序结束");
                return;
            }
            else
            {
                try {
                    int num = Integer.valueOf(str);
                    if (generateMagicSquare(num) != false)
                    {
                        System.out.print("6.txt\t");
                        System.out.println(isLegalMagicSquare("src/P1/txt/6.txt"));
                    }
                } catch (NumberFormatException e) {
                    System.out.println("输入错误!");
                }
            }
        }
    }
}

熟悉Turtle Graphics的各种函数接口,自己编写部分函数,并使用Math库的一些函数实现一些计算以画出所需图形。

(1)Problem 1:Clone and import

a、获取任务代码

从报告里的链接上获取了源文件,在IDEA里建立了相关文件夹后,把下载的源文件放到对应文件夹里,IDEA刷新后修改包名并使用。

b、使用Git管理本地开发

先用Git创建本地仓库,然后和远程仓库连接,git pull拉取代码。

实现一个功能后用git add .上传项目文件,然后commit、push提交到远程仓库上。

(2)Problem 3:Turtle graphics and drawSquare

题目要求使用Turtle类中给出的forward()方法和turn()方法,参数是海龟对象turtle和边长sideLength,最后实现出能够画出边长为指定数值的正方形。

实现思路:

循环执行4次,每次forward前行sideLength的距离,然后画笔方向旋转90度,继续下一次执行。即可得到所要求的正方形。实现结果如下(sideLength = 100):

函数代码如下:

public static void drawSquare(Turtle turtle, int sideLength)
    {
        turtle.color(PenColor.RED);
        for (int i = 0; i < 4; i++)
        {
            turtle.forward(sideLength);
            turtle.turn(90);
        }
    }

(3)Problem 5:Drawing polygons

题目要求实现能够画出正多边形的函数drawRegularPolygon()。

首先需要实现一个辅助函数calculateRegularPolygonAngle()用于计算正多边形的每个内角度数。由数学知识可知,该函数实现如下:

    public static double calculateRegularPolygonAngle(int sides)
    {
        return (sides - 2) * (180.0 / sides);
    }

通过TurtleSoupTest中的Junit测试后再调用calculateRegularPolygonAngle()得出所求正多边形的内角度数,类比画正方形的函数,由数学公式可知,代码实现如下:

    public static void drawRegularPolygon(Turtle turtle, int sides, int sideLength)
    {
        double angle = 180 - calculateRegularPolygonAngle(sides);
        for (int i = 0; i < sides; i++)
        {
            turtle.forward(sideLength);
            turtle.turn(angle);
        }
    }

运行效果如下(边长为100的正六边形):

(4)Problem 6:Calculating Bearings

a、实现 calculateBearingToPoint()

题目要求在已知当前起点和当前朝向角度已知的情况下,计算从起点转动到终点的角度。因此首先使用Math.atan2()函数计算两点之间的边在坐标系中的角度,再减去当前朝向的角度,注意到海龟旋转方向与坐标轴旋转角度方向相反,因此需要取相反数。同样,海龟的基准线是向上,坐标的基准线是向右,因此还需减去90度,最后调整结果在0~360度之间。

代码实现如下:

    public static double calculateBearingToPoint(double currentBearing, int currentX, int currentY, int targetX, int targetY)
    {
        double degree = Math.toDegrees(Math.atan2(targetY - currentY, targetX - currentX));
        degree = (90 - degree) - currentBearing;
        if (degree < 0)
        {
            degree += 360;
        }
        return degree;
    }

运行并通过了Junit测试。

b、实现 calculateBearings()****

题目要求已知若干个点,现在想计算出从第一个点开始到第二个点,第二个点到第三个点……以此类推每次转向的角度。

不妨记有n个点,一开始将“起点”选为第一个点,循环n-1次,每次将i+1个点设置为“终点”,通过calculateBearingToPoint()函数计算旋转角度并保存到List中,再将当前“终点”当做下一次循环的“起点”,继续循环……最后返回List。

代码实现如下:

    public static List<Double> calculateBearings(List<Integer> xCoords, List<Integer> yCoords)
    {
        List<Double> result = new ArrayList<Double>();
        result.add(calculateBearingToPoint(0.0, xCoords.get(0), yCoords.get(0), xCoords.get(1), yCoords.get(1)));
        if (xCoords.size() > 2)
        {
            for (int i = 2; i < xCoords.size(); i++)
            {
                result.add(calculateBearingToPoint(result.get(i - 2), xCoords.get(i - 1), yCoords.get(i - 1), xCoords.get(i), yCoords.get(i)));
            }
        }
        return result;
    }

运行并通过了Junit测试。

(5)Problem 7:Convex Hulls

根据题目提示,运用Gift wrapping algorithm算法,每次都选择转向角最小且点间距离最长的点加入集合中,计算转向角度可使用上题的calculateBearingToPoint函数。其中相同转向角点之间的取舍,可以在循环中使用标记变量Dist_target记录其与当前目标点的距离,如果之后出现了新的目标点,就用Dist_target和计算得到的当前点的距离Dist_temp来比较,取更大者为新的Dist_target。

代码实现如下:

    public static Set<Point> convexHull(Set<Point> points)
    {
        ArrayList<Point> Points_convex = new ArrayList<Point>();
        ArrayList<Point> Points_temp = new ArrayList<Point>();
        Points_temp.addAll(points);
        Set<Point> result = new HashSet<Point>();

        int totalNum = Points_temp.size();
        if (totalNum < 4) // 点集中点小于4时,直接返回
        {
            return points;
        }
        Point Point_first = Points_temp.get(0);
        for (Point Point_now : points)
        { // 找到起始点
            if (Point_now.x() < Point_first.x())
            {
                Point_first = Point_now;
            }
            else if (Point_now.x() == Point_first.x() && Point_now.y() < Point_first.y())
            {
                Point_first = Point_now;
            }
        }
        Points_convex.add(Point_first);//初始点加入集合
        Points_temp.remove(Point_first);//从原始集合中去除初始点

        Point Point_previous = Point_first;
        int count = 0;
        do {
            if (count == 1)
            {
                Points_temp.add(Point_first);//再把原始点加入集合,作为循环的终止条件
            }
            Point Point_target = null;//初始点目标点为空
            double Angle_target = 360;//每次循环找到的最小角度,初始化为360
            double Dist_target = 0;
            for (Point Point_now : Points_temp)
            {
                double Angle_temp = calculateBearingToPoint(0, (int) Point_previous.x(), (int) Point_previous.y(), (int) Point_now.x(), (int) Point_now.y());//计算转向角
                double Dist_temp = Math.pow(Point_previous.x() - Point_now.x(), 2) + Math.pow(Point_previous.y() - Point_now.y(), 2);//计算距离
                if (Angle_temp < Angle_target) //如果转向角比当前找到的最小角度要小,设置新的Angle_target和Dist_target
                {
                    Angle_target = Angle_temp;
                    Point_target = Point_now;
                    Dist_target = Dist_temp;
                }
                else if (Angle_temp == Angle_target && Dist_temp > Dist_target) //取远端点
                {
                    Dist_target = Dist_temp;
                    Point_target = Point_now;
                }
            }
            Points_convex.add(Point_target);
            Points_temp.remove(Point_target);
            Point_previous = Point_target;
            count++;
        } while (Points_convex.get(count) != Point_first);
        result.addAll(Points_convex);
        return result;
    }

运行并通过了Junit测试。

(6)Problem 8:Personal Art

思路:在画正多边形的基础上,步长越来越长,并且角度比画正多边形需要的角度略多一点,每次拐弯变换一次颜色。

其中NumColor是颜色数量,Step是每次变化的步长,Change控制螺旋的密度,其值越大拐弯幅度越大。

效果如下:

代码实现如下(其中Switch语句里设置画笔的颜色):

public static void drawPersonalArt(Turtle turtle)
    {
        int NumColor = 9, Step = 1, Change = 109, Size = 360;
        for (int i = 0; i < Size; i++)
        {
            int temp = i / 18;
            switch (temp % NumColor)
            {
                case 0:
                    turtle.color(PenColor.MAGENTA);
                    break;
                case 1:
                    turtle.color(PenColor.BLUE);
                    break;
                case 2:
                    turtle.color(PenColor.RED);
                    break;
                case 3:
                    turtle.color(PenColor.PINK);
                    break;
                case 4:
                    turtle.color(PenColor.YELLOW);
                    break;
                case 5:
                    turtle.color(PenColor.GREEN);
                    break;
                case 6:
                    turtle.color(PenColor.CYAN);
                    break;
                case 7:
                    turtle.color(PenColor.ORANGE);
                    break;
                case 8:
                    turtle.color(PenColor.GRAY);
                    break;
            }
            turtle.forward(Step * i);
            turtle.turn(360 / NumColor + Change);
        }
    }

(7)Submitting

在CSDN的博客(https://blog.csdn.net/qq_28849009/article/details/104486824)里初步学习了Git的使用。

①到要上传的文件夹里面

cd /d/CODES/GitHub/SoftwareConstruction/HIT-Lab1-120L022408

②初始化本地git仓库

git init

③添加仓库url

git remote add origin https://github.com/ComputerScienceHIT/HIT-Lab1-120L022408

④认证身份

git config --global user.name "XXX"

git config --global user.email "XXX@qq.com"

⑤选择所要上传的文件

git add .

⑥添加修改日志

git commit -m "XXX"

⑦上传文件

git push -u origin master

题目要求设计实现一张社交关系网络图,并编写一个计算人机关系“距离”的函数。网络图基于两个类,分别是FriendshipGraph类和Person类。

(1)设计/实现FriendshipGraph类

每个成员的朋友放在List中,用Graph存取图的映射关系。

public Map<Person,ArrayList<Person>> Graph = new HashMap<Person, ArrayList<Person>>();

a、addVertex(Person People)

用来向people列表加入新的成员,注意需要在加入之前先在图中检测是否有重名的成员,有则输出错误提示并退出。

    public void addVertex(Person People)
    {
        for (Person p : Graph.keySet())
        {
            if (p.getName().equalsIgnoreCase(People.getName()))
            {
                System.out.println(People.getName() + "名称重复!");
                System.exit(0);
            }
        }
        ArrayList<Person> newArray = new ArrayList<Person>();
        this.Graph.put(People, newArray);
    }

b、addEdge(Person People1, Person People2)

函数使用Graph.get(People1).add(People2),在每个人的朋友列表中添加新的朋友。同样,在添加朋友之前先检查被添加朋友的成员在图中是否存在,若不存在则报错并退出。

    public void addEdge(Person People1, Person People2)
    {
        if (Graph.containsKey(People1))
        {
            Graph.get(People1).add(People2);
        }
        else
        {
            System.out.println(People1.getName() + "查无此人!");
            System.exit(0);
        }
    }

c、getDistance(Person People1, Person People2)

该函数首先声明一个ArrayList visited_Person数据结构,来保存已访问过的成员对象。使用邻接表广度搜索的方法,借助队列,先将起点入队,然后执行循环,直到队列为空前:弹出队列头元素,计算当前距离,把弹出点的所有“朋友”入队,并加入visited_Person中,设置距离为先前计算的距离+1。直到找到目标点,返回当前距离。若直到队列为空仍未找到目标点,返回 -1。

public int getDistance(Person People1, Person People2)
    {
        Person Temp = People1, Target = People1;
        int i = 0 , distance = 0;
        Queue<Person> queue_Person = new LinkedList<Person>();
        ArrayList<Person> visited_Person = new ArrayList<Person>();
        if (People1 == People2)
        {
            return distance;
        }
        queue_Person.add(Temp);
        visited_Person.add(Temp);
        while (!queue_Person.isEmpty())
        {
            Temp = queue_Person.poll();
            distance ++;
            while (i < Graph.get(Temp).size())
            {
                Target = Graph.get(Temp).get(i);
                if (Target == People2)
                {
                    return distance; //找到了即返回当前的距离
                }
                if (!visited_Person.contains(Target))
                {
                    queue_Person.add(Target);
                    visited_Person.add(Target);
                }
                i++;
            }
            i = 0;
        }
        return -1;   //找不到说明People1和People2不存在联系
    }

(2)设计实现Person类

Person类:

保存对象名字的字符串private String Name

得到当前对象名字的方法getName()

判断当前对象名字与给定名字是否相同的方法isSameName()

package P3;

public class Person
{
    private final String Name;
    public Person (String Name)
    {
        this.Name = Name;
    }
    public String getName()
    {
        return this.Name;
    }
    public boolean isSameName(String Name)
    {
        return this.Name.equals(Name);
    }
}

(3)设计/实现​​​​​​客户端代码main()**

a、不修改提供的main()的代码

测试结果如下:

b、注释掉“graph.addEdge(rachel, ross)”

测试结果为:

原因是:

从rachel到ross的边不存在了,所以rachel,和ross距离-1,其他点也无法达到。只有getDistance(rachel, rachel)返回0。

c、修改main()输入重复姓名测试

测试结果为:

原因是在前面代码中设置了查找到重复名字就退出的检查:

(4)设计/实现测试用例

根据FriendshipGraph类和Person类设计了一个test检测各种距离和不可到达的情况。

package P3;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class FriendshipGraphTest {

    @Test(expected = AssertionError.class)
    public void testAssertionsEnabled() {
        assert false; // make sure assertions are enabled with VM argument: -ea
    }

    @Test
    public void testBasicFriendshipGraph() throws Exception
    {
        FriendshipGraph graph = new FriendshipGraph();
        Person a = new Person("a");
        Person b = new Person("b");
        Person c = new Person("c");
        Person d = new Person("d");
        graph.addVertex(a);
        graph.addVertex(b);
        graph.addVertex(c);
        graph.addVertex(d);
        graph.addEdge(a, b);
        graph.addEdge(b, c);
        graph.addEdge(c, d);
        assertEquals("expected distance", 1, graph.getDistance(a, b));
        assertEquals("expected distance", 1, graph.getDistance(b, c));
        assertEquals("expected distance", 1, graph.getDistance(c, d));
        assertEquals("expected distance", 2, graph.getDistance(a, c));
        assertEquals("expected distance", 2, graph.getDistance(b, d));
        assertEquals("expected distance", 3, graph.getDistance(a, d));
        assertEquals("expected distance", -1, graph.getDistance(b, a));
    }

}

四、实验收获

对java语言的掌握十分不足,下一次实验前需要加强。

认识到了趁手的工具软件对程序员的帮助有多大,“工欲善其事必先利其器”,下一次实验前将配置好更得心应手的工具软件。

(1)Java编程语言是否对你的口味?与你熟悉的其他编程语言相比,Java有何优势和不足?

非常对我的口味,具体就是有很多数据结构直接可以使用,Java提供的库函数功能十分强大,深受我的喜爱。

在此之前,我只熟悉C语言,相比之下,Java相较于C语言的优点是:C语言特别简陋,许多常用的数据结构的实现都需要自己重新编写;而Java简单易上手。缺点是:C语言更接近程序的底层逻辑,运行效率更高,且更能锻炼程序员的基础能力;而Java并不能使程序员了解一些数据结构的具体实现。

(2)关于Eclipse或IntelliJ IDEA,它们作为IDE的优势和不足;

在2021夏季小学期开始使用过Eclipse,小学期快结束时接触到了IDEA,因此我对其感受颇深。Eclipse的优势在于其免费,其余无任何优势。IDEA的优势在于插件丰富,集成更智能,界面更美观,使用十分舒心,不足在于旗舰版收费,但可使用学生邮箱认证身份来免费使用。

(3)关于Git和GitHub,是否感受到了它在版本控制方面的价值;

需要继续学习才能熟练掌握使用。

(4)关于CMU和MIT的作业,你有何感受;

能够向世界一流计算机专业学习是迈向世界一流的必经之路。

(5)关于本实验的工作量、难度、deadline;

工作量大,难度不小,deadline撞车《形式语言与自动机》课程的期末考试,因此时间十分紧张,高强度学习知识并编写代码的同时很难统筹兼顾其他课程的复习与预习。

(6)关于初接触“软件构造”课程;

有趣,可学习性强,颇有难度,英语阅读困难。

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器