This experiment trained basic Java programming skills by solving three questions, able to develop basic functional modules with Java OO, able to read and understand existing code frameworks and complete codes according to functional requirements, able to write basic test programs for the developed codes and complete the tests. Initial assurance of the correctness of the developed code. On the other hand, using Git as a tool for code configuration management, learn how to use Git. Basic Java OO programming based on Eclipse IDE Java programming based on Junit test based on Git code configuration management 2 experimental environment configuration 2.1 IDE the compiler I choose for this experiment is IntelliJ IDEA

Download Git from the web and complete the configuration according to this tutorial

2.3 JUnit There was no JUnit support when JUnit was tested, so download JUnit to an external library

2.4 making warehouse

After reading the experiment guide, MagicSquare is a Magic square problem that needs to implement the following two functions:

  1. Read magic squares from files and determine if they are valid
  2. Generates an odd number of magic squares and saves them in a file

Therefore, we need to master the ability of reading and writing files and the ability to judge whether magic squares are legitimate. Read matrix information from the file and store it in a two-dimensional array 2. Judge whether the magic square read is legitimate from the following aspects: A. Whether the number of rows and columns to be stored is equal b. Whether the data type to be stored is int C. Is it TAB 3 that splits the data. If it’s a valid matrix, we determine whether the sum of the rows and columns and the diagonals are equal and determine whether it’s magic square 4. Return true if yes, false if no and why

Storing matrix elements in a two-dimensional array is illegal if the elements are not tab-separated

There are non-int numbers

Have a negative

If both are valid, store the sum of the row and column diagonally in the array. If all the elements in the array are equal, it is a magic square

Design results: five TXT files are tested, the results are as follows

3.1.2 generateMagicSquare() Flow chart:

Function analysis: at the time of initialization, first place 1 in the middle of the first line, and then in sequence to the back of the Numbers in the square in the upper right pane, it is important to note when the upper right pane out, you need to imagine matrix to infinity, then imagine the other side of the matrix corresponding to the actual matrix into. If the number is already in the upper right square, place the number in the square directly below the current square, and then we can repeat the above steps until all the squares are filled. Exception analysis: if n is even, the error message is: Thrown to indicate that an array has been accessed with an illegal index. The index is either negative or greater than or equal to the size of the arra. This is because at initialization row=n-1, and then the loop says n-1%n==0, so row++ causes row=n, and the array is out of bounds. If n is negative, the error message is Thrown if an application tries to create an array with negative size. This is because arrays cannot be indexed with negative numbers. Design result: odd number

An even number

A negative number

This problem uses the Turtle Graphics package that requires us to use the Turtle Graphics package to implement functions including drawing squares, calculating and drawing arbitrary regular polygons, calculating deflection angles, convex hull problems, and drawing your own art Graphics. It is worth noting that these functions should be able to call each other. 3.2.1 Problem 1: Clone and import from github.com/rainywang/S… Lab1-1190200704/ SRC, you can get the corresponding file of P2. The action in IntelliJ is to mark P2 as the source root and start manipulating the code. To draw a square, just go to sideLength and rotate 90 degrees, repeat four times.

The sum of the interior angles of a polygon is (number of sides -2)*180°, so the Angle of each rotation is (number of sides -2)*180°/ number of sides. You just need to go to sideLength and rotate it to get the degree, repeat n times.

3.2.4 Problem 6: To return the Angle from the origin (0,0) to (targetx-currentx, targety-currenty) in calculateBearingToPoint This is the Angle between the starting point and the target point, and it’s important to remember that this is relative to the positive X-axis.

You subtract 90 degrees from the Angle and the given currentBearing

Because it can’t be negative, we have to add 360 degrees in the negative case.

The test results are as follows:

If the number of Convex Hulls is less than 3, then we directly return,

Otherwise we choose the bottom-left point as the startPoint.

We’re going to find the nextPoint, nextPoint, by calling calculateBearingToPoint to find the smallest Angle with currentPoint,

It is worth noting that in the case that multiple points have the smallest Angle, the point farthest from the currentPoint needs to be found.

Until nextPoint finds startPoint, the set of points is the convex hull. The test results are as follows

3.2.6 Problem 8: Personal Art Calls drawRegularPolygon to draw hexagons. In order to make colors more colorful, colors in PenColor are used to transform in order to create a dynamic aesthetic feeling of order in the graph.

3.2.7 Generating public and private keys in Powershell

Copy the generated public key to Github

Copy the GIthub repository SSH address

Add remote to github repository in Intellij

3.3 Social Network This task requires various operations on directed graphs, including adding points, adding edges, calculating distances and relationships between points, etc. The significance of this experiment in reality lies in that it can directly show the relationship between characters. In the operation, some details are also dealt with, such as the names of people should not be the same. 3.3.1 Design/implement the FriendshipGraph class

AddVertex = addVertex = addVertex = addVertex = addVertex = addVertex = addVertex = addVertex = addVertex

Construct addEdge to add edges by calling the makeFriend function in the Person class to connect unrelated two people in one direction, excluding the case where the connection was not created

I also need to read the shortest distance between two people, and I use the breadth-first traversal algorithm that I learned in data structures. Add the start node to the queue, and in the loop read the queue head, i.e. out of the queue. The read head is the current node, traverse around the node as many nodes as it can reach, and then add the surrounding nodes in turn to the queue and set the distance weight of the node to store in the distanceMap. Repeat the above operation layer by layer until the destination node is found, or the queue is empty. If the queue is empty and the destination node is not found, then the node is unreachable and -1 is returned.

The implementation of the Person class is relatively simple, the first thing to achieve reading the name

Construct makeFriend to add new friends to friendList

Construct isFriend to check if the friend is in the list.

3.3.3 Design/Implementation of client code Main () Main function has been given in the report as follows

Delete the social relationship between Rachel -> RossCopy the code

We are asked to change Ross to Rachel, and the result is as followsCopy the code

3.3.4 Designing/Implementing test Cases We create a directed graph as follows

Here’s a test example

The results of the test are as follows