Java Lab report (experiment three)

Source: Internet
Author: User
Tags coding standards gettext version control system

Lesson: Java Programming Class: 1351

Name: Wang Wei No.: 20135116

Score: Instructor: Lou Jia Peng Experimental Date: 2015.06.03

Experiment level: Preview degree: Experiment time: 14:00~20:00

Instrument Group: Compulsory/Elective: Elective experiment number: 3

Experiment Name: Agile Development and XP practice

Experimental purposes and requirements:

1. Students who do not have a Linux base are advised to start with the Linux basics (new version) Vim Editor course

2. Complete the experiment, write the experiment Report, the experiment report is published in the blog Garden, note that the experiment report focuses on the running results , problems encountered (tool find, installation, use, program editing, debugging, running, etc.), solutions (empty methods such as "Check the network", "Ask classmates", "reading" and so on all get 0 points) and analysis (from which can get what revelation, what harvest, lessons, etc.). The report can refer to the guidance of Fan Fei Dragon Teacher

3. Plagiarism is strictly forbidden, and the results of the experiment of the perpetrator are zero, and other punitive measures are added.

Experimental instrument:

Name

Model

Number

Pc

1

Virtual machines

Laboratory Building

1

First, the contents of the experiment:

1. XP Basics

2. XP Core Practice

3. Related Tools

Second, the experimental process:

(i) Agile Development and XP

Software = Program Plus software engineering

Software enterprise = Software + business model

    • RUP (Rational Unified Process)
    • PSP (Personal software Process)
    • TSP (Team software Process)
    • Agile Process
    • ......

Agile Development (development) is a human-centric, iterative, and progressive approach to development. "Agile Processes" are a collection of values and methodologies.

    • XP is a methodology developed to target software that meets customer needs
    • XP is a practice-based software engineering process and thought
    • XP believes that code quality is more important than people generally think.

XP software development is what is expressed through the XP guidelines:

    • Communication: XP believes that communication between project members is key to the success of the project and regards communication as the main driver of coordination and cooperation in the project.
    • Simple: XP assumes that the future cannot be reliably predicted, and it is economically unwise to consider it now, so you should not think too much about the future but should focus on the urgent needs.
    • Feedback: XP considers the system itself and its code to be a reliable basis for reporting on the progress and status of the system development. The feedback of system development status can be used as a means to determine the progress of system development and determine the next development direction of the system.
    • Courage: It represents XP's view that people are one of the most important aspects of software development. In the development of a software product human participation throughout its entire life cycle, is the courage to eliminate the dilemma, let the team to the local optimal left behind, to achieve more significant goals. Demonstrates XP's basic trust in "people make projects successful".

The basis for successful use of a practice in an XP environment is presented through the rules of XP, including: Quick feedback, hypothesis simplicity, incremental changes, advocating for change, and quality of work.

XP software development is the cornerstone of XP activities, including: coding, testing, listening, design.

(ii) Coding standards

In the virtual machine, Eclipse enters the following code:

This code cannot see the hierarchy because there is no basic indentation.

Click Source->format in the Eclipse menu or use the shortcut key ctrl+shift+f to indent the specification as specified by Eclipse, with the following effect:

The general naming conventions in Java are:

    • To embody their own meanings.
    • Terms for packages, classes, variables
    • Method name with movable bin
    • Package name all lowercase, such as: IO,AWT
    • The first letter of the class name should be capitalized, such as: Helloworldapp
    • The first letter of a variable name is lowercase, such as: UserName
    • The first letter of the method name is lowercase: setName

(iii) Pair programming

Pairing programming is an important practice in XP. In pair programming mode, a pair of programmers work side-by-shoulder, equally, and in complementary way. They sit in front of a computer, facing the same monitor, working with the same keyboard and the same mouse. They analyze together, design together, write test cases together, encode together, do unit tests together, do integration testing together, write documents together, and so on.

(iv) version control

By working in different pairs, all programmers can see the full code. One of the main advantages of collective ownership is to increase the speed of the development process, because any programmer can fix it once there is an error in the code. This means that the code is placed in a place where everyone can easily get it, and we call it a code repository. In this experiment, I also opened my own code base. My Code base link is http://git.shiyanlou.com/20135116

(v) Reconstruction

Let's look at the concept of refactoring first:

Refactoring (refactor) is to change the structure within the software without changing the external behavior of the software, making it easier to read, easy to maintain, and easy to change.

Examples are as follows:

1. Use refactoring to modify the name:

To modify the method, click the name you want to change with your mouse, select the Refactor->rename in the Eclipse menu ... : The effect is as follows:

2. Use Refactoring for encapsulation:

The basic code is as follows:

Using the Refactor->encapsulate Field ... in the Eclipse menu, the Name,age,id is encapsulated with the following effect:

Use Eclipse in Source->generate toString () ... Generates a ToString method for the student class

and modify the code in main:

System.out.println (S.tostring ());

3. About modifying the code:

The first thing in the stink is duplicated code. If you see the same program structure in more than one place, then you can be sure that if you try to combine them, the program will become better.

    • The simplest duplicated code is [two methods within the same class that contain the same expression]. All you need to do is use Extract method to extract the duplicated code, and then let the two locations invoke the extracted piece of code.
    • Another common scenario is that [two siblings (sibling) subclasses contain the same expression]. To avoid this, you only need to use the Extract method for two classes, and then use the pull-up method for the extracted code to push it into the superclass.
    • If the code is just similar, not exactly the same, then you have to use Extract method to split the similarity and difference sections into a single method. Then you might find that you might be able to use the form template method to get a template method design pattern.
    • If some methods do the same thing with different algorithms, you can choose a clearer one, and use substitute algorithm to replace the algorithm of other methods.
    • If duplicaded code appears in two unrelated classes, you should consider using the extract class for one, refining the duplicate code into a separate class, and then using the new class within another class. However, the method of repeating the code may indeed belong to only one class, the other class can only invoke it, or the method may belong to the third class, and the other two classes should refer to the third class. You have to decide where this method fits best and make sure that it is placed and will not appear anywhere else.

4. The complete process of refactoring includes:

    1. Check out code from the version control system library
    2. Read code (including test code)
    3. Find Bad smell
    4. Refactoring
    5. Run all the unit Tests

Check in code to codebase

(vi) Practical projects

1. Project brief: Edit a simple watch game.

Need to implement (1) a 6 row column of the main panel, show the number of participating games, (2) according to the player's choice of two number, to determine whether the two number is the same, if the same is eliminated, otherwise, until all the number is eliminated, the game is the end; (3) When the player cannot find the same number, you can use "Re-column" button to rearrange the current game, (4) The game starts again when the player chooses the "Come Again" button, (5) The game ends when the player chooses the "Exit" button.

2. The game code is as follows:

Package Lianliankan;

Import javax.swing.*;
Import java.awt.*;
Import java.awt.event.*;

public class Lianliankan implements ActionListener {
JFrame MainFrame; Main panel
Container Thiscontainer;
JPanel Centerpanel, Southpanel, Northpanel; Sub-panel
JButton diamondsbutton[][] = new jbutton[6][5];//game button array
JButton Exitbutton, Resetbutton, Newlybutton; Exit, re-column, Start button
JLabel fractionlable = new JLabel ("0"); Score Label
JButton Firstbutton, Secondbutton; Record two selected buttons separately
int grid[][] = new int[8][7];//save Game button position
static Boolean pressinformation = false; Determine if a button is selected
int x0 = 0, y0 = 0, x = 0, y = 0, fristmsg = 0, secondmsg = 0, Validatelv; Position coordinates of the game button
int I, j, K, n;//elimination method control

public void init () {
MainFrame = new JFrame ("jkj");
Thiscontainer = Mainframe.getcontentpane ();
Thiscontainer.setlayout (New BorderLayout ());
Centerpanel = new JPanel ();
Southpanel = new JPanel ();
Northpanel = new JPanel ();
Thiscontainer.add (Centerpanel, "Center");
Thiscontainer.add (Southpanel, "South");
Thiscontainer.add (Northpanel, "North");
Centerpanel.setlayout (New GridLayout (6, 5));
for (int cols = 0; cols < 6; cols++) {
for (int rows = 0; rows < 5; rows++) {
Diamondsbutton[cols][rows] = new JButton (
String.valueof (grid[cols + 1][rows + 1]));
Diamondsbutton[cols][rows].addactionlistener (this);
Centerpanel.add (Diamondsbutton[cols][rows]);
}
}
Exitbutton = new JButton ("Exit");
Exitbutton.addactionlistener (this);
Resetbutton = new JButton ("Re-column");
Resetbutton.addactionlistener (this);
Newlybutton = new JButton ("One More Game");
Newlybutton.addactionlistener (this);
Southpanel.add (Exitbutton);
Southpanel.add (Resetbutton);
Southpanel.add (Newlybutton);
Fractionlable.settext (String.valueof (Integer.parseint (fractionlable
. GetText ())));
Northpanel.add (fractionlable);
Mainframe.setbounds (280, 100, 500, 450);
Mainframe.setvisible (TRUE);
}

public void Randombuild () {
int randoms, cols, rows;
for (int twins = 1; twins <=; twins++) {
randoms = (int) (Math.random () * 25 + 1);
for (int alike = 1; alike <= 2; alike++) {
cols = (int) (Math.random () * 6 + 1);
rows = (int) (Math.random () * 5 + 1);
while (grid[cols][rows]! = 0) {
cols = (int) (Math.random () * 6 + 1);
rows = (int) (Math.random () * 5 + 1);
}
This.grid[cols][rows] = randoms;
}
}
}

public void fraction () {
Fractionlable.settext (String.valueof (Integer.parseint (fractionlable
. GetText ()) + 100));
}

public void Reload () {
int save[] = new INT[30];
int n = 0, cols, rows;
int grid[][] = new INT[8][7];
for (int i = 0, I <= 6; i++) {
for (int j = 0; J <= 5; j + +) {
if (this.grid[i][j]! = 0) {
Save[n] = thi S.GRID[I][J];
n++;
}
}
}
N = n-1;
This.grid = grid;
while (n >= 0) {
cols = (int) (Math.random () * 6 + 1);
rows = (int) (Math.random () * 5 + 1);
while (grid[cols][rows]! = 0) {
cols = (int) (Math.random () * 6 + 1);
rows = (int) (Math.random () * 5 + 1);
}
This.grid[cols][rows] = save[n];
n--;
}
Mainframe.setvisible (false);
Pressinformation = false; Be sure to classify the button click information as the initial
init ();
for (int i = 0, i < 6; i++) {
for (int j = 0; J < 5; J + +) {
if (grid[i + 1][j + 1] = = 0)
diamondsbutton[i][ J].setvisible (FALSE);
}
}
}

public void Estimateeven (int placex, int placey, JButton BZ) {
if (pressinformation = = False) {
x = Placex;
y = Placey;
Secondmsg = Grid[x][y];
Secondbutton = BZ;
Pressinformation = true;
} else {
x0 = x;
y0 = y;
Fristmsg = secondmsg;
Firstbutton = Secondbutton;
x = Placex;
y = Placey;
Secondmsg = Grid[x][y];
Secondbutton = BZ;
if (fristmsg = = Secondmsg && Secondbutton! = Firstbutton) {
Xiao ();
}
}
}

public void Xiao () {////The same situation can be eliminated. Careful analysis, there are no comments
if (x0 = = x && (y0 = = y + 1 | | y0 = y-1))
|| ((x0 = = x + 1 | | x0 = = x-1) && (y0 = = y))) {//Determine if adjacent
Remove ();
} else {
for (j = 0; J < 7; J + +) {
if (grid[x0][j] = = 0) {//Determine which button is empty for the first button
if (Y > J) {//If the y-coordinate of the second button is greater than the y-coordinate of the null button the first button is to the left of the second button
for (i = y-1; I >= J; i--) {//Judging the left side of the second button until there is no button in the middle of the first button
if (grid[x][i]! = 0) {
k = 0;
Break
} else {
K = 1;
}//K=1 instructions passed the first validation
}
if (k = = 1) {
Linepassone ();
}
}
if (Y < J) {//If the y-coordinate of the second button is less than the y-coordinate of the null button the first button is to the right of the second button
for (i = y + 1; I <= J; i++) {//Judging the left of the second button until there is no button in the middle of the first button
if (grid[x][i]! = 0) {
k = 0;
Break
} else {
K = 1;
}
}
if (k = = 1) {
Linepassone ();
}
}
if (y = = j) {
Linepassone ();
}
}
if (k = = 2) {
if (x0 = = x) {
Remove ();
}
if (x0 < x) {
for (n = x0; n <= x-1; n++) {
if (grid[n][j]! = 0) {
k = 0;
Break
}
if (grid[n][j] = = 0 && n = = x-1) {
Remove ();
}
}
}
if (x0 > x) {
for (n = x0; n >= x + 1; n--) {
if (grid[n][j]! = 0) {
k = 0;
Break
}
if (grid[n][j] = = 0 && N = = x + 1) {
Remove ();
}
}
}
}
}
for (i = 0; i < 8; i++) {//Column
if (grid[i][y0] = = 0) {
if (x > i) {
for (j = x-1; J >= i; j--) {
if (grid[j][y]! = 0) {
k = 0;
Break
} else {
K = 1;
}
}
if (k = = 1) {
Rowpassone ();
}
}
if (x < i) {
for (j = x + 1; j <= I; j + +) {
if (grid[j][y]! = 0) {
k = 0;
Break
} else {
K = 1;
}
}
if (k = = 1) {
Rowpassone ();
}
}
if (x = = i) {
Rowpassone ();
}
}
if (k = = 2) {
if (y0 = = y) {
Remove ();
}
if (Y0 < y) {
for (n = y0; n <= y-1; n++) {
if (grid[i][n]! = 0) {
k = 0;
Break
}
if (grid[i][n] = = 0 && n = = y-1) {
Remove ();
}
}
}
if (y0 > Y) {
for (n = y0; n >= y + 1; n--) {
if (grid[i][n]! = 0) {
k = 0;
Break
}
if (grid[i][n] = = 0 && N = = y + 1) {
Remove ();
}
}
}
}
}
}
}

public void Linepassone () {
if (Y0 > J) {//First button peer empty button on left
for (i = y0-1; I >= J; i--) {//To determine if there is a button between the first button and the left empty button
if (grid[x0][i]! = 0) {
k = 0;
Break
} else {
K = 2;
}//k=2 instructions passed the second validation
}
}
if (Y0 < J) {//First button peer empty button between and second button
for (i = y0 + 1; I <= J; i++) {
if (grid[x0][i]! = 0) {
k = 0;
Break
} else {
K = 2;
}
}
}
}

public void Rowpassone () {
if (x0 > i) {
for (j = x0-1; J >= i; j--) {
if (grid[j][y0]! = 0) {
k = 0;
Break
} else {
K = 2;
}
}
}
if (x0 < i) {
for (j = x0 + 1; j <= I; j + +) {
if (grid[j][y0]! = 0) {
k = 0;
Break
} else {
K = 2;
}
}
}
}

public void Remove () {
Firstbutton.setvisible (FALSE);
Secondbutton.setvisible (FALSE);
Fraction ();
Pressinformation = false;
k = 0;
GRID[X0][Y0] = 0;
Grid[x][y] = 0;
}

public void actionperformed (ActionEvent e) {
if (e.getsource () = = Newlybutton) {
int grid[][] = new INT[8][7];
This.grid = grid;
Randombuild ();
Mainframe.setvisible (FALSE);
Pressinformation = false;
Init ();
}
if (e.getsource () = = Exitbutton)
System.exit (0);
if (e.getsource () = = Resetbutton)
Reload ();
for (int cols = 0; cols < 6; cols++) {
for (int rows = 0; rows < 5; rows++) {
if (e.getsource () = = Diamondsbutton[cols][rows])
Estimateeven (cols + 1, rows + 1, diamondsbutton[cols][rows]);
}
}
}

public static void Main (string[] args) {
Lianliankan llk = new Lianliankan ();
Llk.randombuild ();
Llk.init ();
}
}

3. Group Division of Work (Group members: 20135109 Gao Yi Tong Blog address: http://www.cnblogs.com/gyt0520/archive/2015/06.html,20135116 Wang Yuyi)

Gao Yi: Write judgment operation, determine whether the player selected two number is consistent, if the same is eliminated, otherwise the interface is unchanged.

Wang Wei: Write the settings for the page space, such as "re-column", "Come Again", "exit" button in the game.

4. Test Results Demo

Re-column Demo:

End of game:

Third, the problems encountered and solutions

1. Failure to write TDD as required

Solution: From the online access to data, and combined with the last experimental process, understand the meaning and role of TDD, but just stay in the level of understanding, but also can not do their own flexibility to write, use;

2. The code written in the lab building could not be hosted in Git.

Solution: According to the experimental building in the experiment three of the requirements of the actual operation, and opened my code base, but did not really use the code base. We still wrote the game code written in pair practice in our eclipse, and failed to put it into the code base for hosting.

Iv. Harvest of Experiments

  In this experiment, I first learned to use format from source in eclipse to automate the layout of cluttered code to make it more readable. At the same time, in this experiment, I also learned a lot of refactoring related operations, this also for me in the future Java learning process to provide a certain skill, appear to be compared to the level, no longer like just touch Java, each step will only be the steps to operate, may in the intangible also for me to save a certain time.

I think the most challenging thing in this experiment is pairing a little game. When I first heard the experiment, I really thought it was going to collapse ... But fortunately, in cooperation with my teammates, we first found some relevant code on the Internet, and to understand it in a segmented. By working hard, we have mastered the essence of this game principle. Because of the limited level of our two, we cannot make a deeper change to it. After this experiment, I feel that my ability to read code has been improved, but the ability to write code on their own needs to be strengthened, which also motivates me in the course of learning, to continue to learn the teachers, students of the programming ideas and methods, dare to challenge themselves, try to write some valuable code.

Five, TIME statistics

Steps

Take

Percentage

Demand analysis

1h

16.7%

Design

1h 16.7%

Code implementation

2h 33.2%

Test

1h 16.7%

Analysis Summary

1h 16.7%

Java Lab report (experiment three)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.