Java Second Experiment

Source: Internet
Author: User

20145336 Two week Java Lab report 20145336 "Java Programming" second experimental report

Experimental report of Beijing Institute of Electronic Technology (BESTI)

Course: Java programming

class:1453

Name: Zhang Ziyang

Instructor : Lou Jia Peng

date of experiment:2016.04.12

Experiment Name: Familiarity with the Java development environment (Linux + Eclipse)

Experimental content:
    1. Initial mastery of unit testing and TDD

    2. Understanding and mastering object-oriented three elements: encapsulation, inheritance, polymorphism

    3. Initial mastery of UML modeling

    4. Familiarity with S.O.L.I.D principles

    5. Understanding Design Patterns

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 site blog, note that the experimental report is focused on the results of the operation, problems encountered (tool search, installation, use, program editing, commissioning, operation, etc.), solutions (empty methods such as "Check Network", "Ask classmates", "reading" 0 points) as well as analysis (what can be learned from it, what gains, lessons, etc.). The report can refer to the guidance of Fan Fei Dragon Teacher

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

    2. Please first in the laboratory building in the ~/code directory with their own school number to create a directory, code and UML diagram to be placed in this directory, no study number will require redo, and then follow the following steps to practice.

Experimental steps

Unit Test

1. Three kinds of code: pseudo-code, product code, test code. We should write pseudocode----and then translate it into product code, and finally write test code in a specific programming language to verify that your code has no problem.

(1) Pseudo-code

百分制转五分制:如果成绩小于60,转成“不及格”如果成绩在60与70之间,转成“及格”如果成绩在70与80之间,转成“中等”如果成绩在80与90之间,转成“良好”如果成绩在90与100之间,转成“优秀”其他,转成“错误”

(2) Product Code

public class MyUtil{public static String percentage2fivegrade(int grade){    //如果成绩小于60,转成“不及格”    if (grade < 60)        return "不及格";        //如果成绩在60与70之间,转成“及格”    else if (grade < 70)        return "及格";        //如果成绩在70与80之间,转成“中等”    else if (grade < 80)        return "中等";        //如果成绩在80与90之间,转成“良好”    else if (grade < 90)        return "良好";        //如果成绩在90与100之间,转成“优秀”    else if (grade < 100)        return "优秀";        //其他,转成“错误”    else        return "错误";}}

(3) test code

When testing with 50 points:

public class MyUtilTest {public static void main(String[] args) {// 百分制成绩是50时应该返回五级制的“不及格”if(MyUtil.percentage2fivegrade(50) != "不及格")    System.out.println("test failed!");else    System.out.println("test passed!");}}

Increase the judgment on the negative score:

public class MyUtil3{public static String percentage2fivegrade(int grade){    //如果成绩小于0,转成“错误”    if ((grade < 0))        return "错误";        //如果成绩小于60,转成“不及格”    else if (grade < 60)        return "不及格";        //如果成绩在60与70之间,转成“及格”    else if (grade < 70)        return "及格";        //如果成绩在70与80之间,转成“中等”    else if (grade < 80)        return "中等";        //如果成绩在80与90之间,转成“良好”    else if (grade < 90)        return "良好";        //如果成绩在90与100之间,转成“优秀”    else if (grade <= 100)        return "优秀";        //如果成绩大于100,转成“错误”    else        return "错误";}}

Test boundary conditions:

public class MyUtilTest4{public static void main(String[] args) {    //测试边界情况    if(MyUtil2.percentage2fivegrade(0) != "不及格")        System.out.println("test failed 1!");    else if(MyUtil2.percentage2fivegrade(60) != "及格")        System.out.println("test failed 2!");    else if(MyUtil2.percentage2fivegrade(70) != "中等")        System.out.println("test failed 3!");    else if(MyUtil2.percentage2fivegrade(80) != "良好")        System.out.println("test failed 4!");    else if(MyUtil2.percentage2fivegrade(90) != "优秀")        System.out.println("test failed 5!");    else if(MyUtil3.percentage2fivegrade(100) != "优秀")        System.out.println("test failed 6!");    else        System.out.println("test passed!");}}
Tdd

Tdd:test driven devlopment, test-driven development. Write the test code first, and then write the product Code development method. The general steps of TDD are as follows: Clear the current functionality to be completed, log into a test list, and quickly complete the test case for this function. Code compilation does not pass (no product code) write product code test by refactoring the code, and ensure that the test through (refactoring next lab) loop to complete all the functions of the development

Object-oriented three elements-abstract

That is, the process of "seeking common ground and refine". The process of stripping together the same parts of several things and forming a product with a specific function is an abstraction. The result of the process abstraction is the function, and the result of the data abstraction is the abstract data type its obvious benefit is that (in the program design) The code is reduced in large repetition and improves efficiency.

-Encapsulation, inheritance and polymorphism

The three elements of object-oriented (object-oriented) include: encapsulation, inheritance, polymorphism. Object-oriented thinking involves all aspects of software development, such as object-oriented analysis (OOA), Object-oriented design (OOD), and object-oriented programming (OOP). OOA decomposes The system according to the abstract key problem domain and focuses on what. Ood is an object-oriented implementation of the symbolic design system, which constructs the system into a "real-world" object in a way that is very close to the problem domain terminology, and focuses on how to implement the functional specification through the model. OOP is coded in a programming language (such as Java) on a design basis. Encapsulation: will be with a certain data and related behavior to be wrapped together to realize the information is hidden, the core content is modular and information hiding, and this is accompanied by the use of the interface.

Code
Package Shiyan2;public class complexnumber{double R,i;public ComplexNumber () {this.r=0;this.i=0;} Public ComplexNumber (Double R, double i) {this.r=r;this.i=i;} Public double Getrealpart () {return THIS.R;} Public double Getimaginarypart () {return this.i;} public void Setrealpart (double R) {this.r=r;} public void Setimaginarypart (double i) {this.i=i;}  Public ComplexNumber Complexadd (ComplexNumber a,complexnumber b) {ComplexNumber temp = new ComplexNumber (); TEMP.R = A.R + b.r;temp.i = a.i + B.i;return temp;}  Public ComplexNumber Complexminus (ComplexNumber a,complexnumber b) {ComplexNumber temp =new ComplexNumber (); TEMP.R=A.R    -B.r;temp.i =a.i-b.i;return temp;} Public ComplexNumber Complexmulti (ComplexNumber a,complexnumber b) {ComplexNumber temp = new ComplexNumber (); TEMP.R = a . r*b.r-a.i*b.i;temp.i = A.r*b.i+a.i*b.r;return temp;} public void Complexadd (ComplexNumber c) {this.r=this.r+c.r;this.i=this.i+c.i;} public void Complexminus (ComplexNumber c) {this.r=this.r-c.r;this.i=this.i-c.i;} Public void Complexmulti (ComplexNumber c) {double TEMP=THIS.R; This.r=this.r*c.r-this.i*c.i;this.i =TEMP*C.I+THIS.I*C.R;} public void Printcomplexnumber () {System.out.print ("" "+this.r+" + "+this.i+" I ");}}

The test code is as follows: Package shiyan2;

public class txet extends ComplexNumber{public static void main(String[] args)        //测试代码{    ComplexNumber cc=new ComplexNumber(4,5);    cc.printComplexNumber();    System.out.println();    ComplexNumber dd=new ComplexNumber(2,4);    dd.printComplexNumber();    System.out.println();    System.out.println("-----------------");    System.out.println();    ComplexNumber ff=new ComplexNumber();    ff=ff.ComplexAdd(cc,dd);    ff.printComplexNumber();    System.out.println();    ff=ff.ComplexMinus(cc,dd);    ff.printComplexNumber();    System.out.println();    ff=ff.ComplexMulti(cc,dd);    ff.printComplexNumber();    System.out.println();    System.out.println("-----------------");}}
最终结果:

Experience

This is the second experiment, the feeling is still very difficult, did not do it several times. Or after the help of the students to complete the experiment. Still need to work hard to learn Java knowledge, the next experiment can make progress.

PSP Time
Steps time: 100 minutes percentage
Demand analysis 17 minutes 17%
Design 18 minutes 18%
Code implementation 40 minutes 60g
Test 15 minutes 15%
Analysis Summary 10 minutes 10%

Java Second Experiment

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.