20145331 2nd Experimental Report on Java programming

Source: Internet
Author: User

20145331 Java Programming 2nd Experiment Report two Java object-oriented programming one, experimental content

1. Initial mastery of unit testing and TDD

2. Understanding and mastering the 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

Second, the experimental 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 put in this directory, no study number will be required to redo, and then follow the following steps to practice.

Third, the experimental Steps (a) unit test

(1) Three kinds of code: pseudo Code, product code, test code.

A. Pseudo-code

Percentile five-point system:

If the score is less than 60, turn into "fail"

If the score is between 60 and 70, turn into "pass"

If the score is between 70 and 80, turn into "medium"

If the score is between 80 and 90, turn into "good"

If the score is between 90 and 100, turn into "good"

Other, turn into "error"

B. 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 "错误";}}

C. Test code input is "50"

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!");}}

(2) TDD (test driven devlopment, testing-driven development):

• Clear the current functionality to be completed and record it as a test list

• Quickly finish writing test cases for this feature

• Test code compilation does not pass

• Write the Product code

• Test Pass

• Refactor the code and ensure that the test passes

• Cycle through the development of all functions

(ii) Object-oriented three elements

(1) 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.

(2) encapsulation, inheritance and polymorphic object-oriented (object-oriented) Three elements 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. The main line that runs through OOA, Ood, and OOP is abstraction. Ood Modeling uses the graphical Modeling language UML (Unified Modeling Language), UML is a generic modeling language.

• Encapsulation: The use of interfaces is accompanied by the fact that the data and related behaviors are packaged together to achieve information hiding, and the core content is modularity and information hiding.

(iii) Preliminary design pattern

SRP (single Responsibility Principle, sole responsibility principle)

OCP (open-closed Principle, open-closed principle)

LSP (Liskov substitusion Principle,liskov substitution principle)

ISP (Interface segregation Principle, interface separation principle)

Dip (Dependency inversion Principle, dependency inversion principle)

(iv) Practice

Use TDD to design the complex to implement the plural class.

Pseudo code:

1, the real part of the complex number is 0, the imaginary part is 0

2, the real part of the complex is 0, the imaginary part is the corresponding number

3, the real part of the plural is the corresponding number, the real part is 0

4. The two parameters are the real part and the imaginary part respectively.

5. Realize the addition, subtraction and multiplication of two complex numbers.

A. Pseudo-code:

Two variables, real part realpart and imaginary part Imaginarypart. SH Xu

Sum of complex numbers = (real + real) + (imaginary + imaginary part) I

Plural subtraction = (real part-real) + (imaginary part-imaginary part) I

Print a complex number

B. Product Code:

 public class Complex {private int sh,xu;    Complex () {this.sh=0; this.xu=0;}    Complex (int sh) {this.sh=sh; this.xu=0;}    Complex (int sh,int xu) {this.sh=sh; This.xu=xu;}    public void Addfu (Complex p1,complex p2) {System.out.println ("The sum of these two complex numbers is:");    this.sh=p1.sh+p2.sh;    This.xu=p1.xu+p2.xu; Print ();}    public void Minusfu (Complex p1,complex p2) {System.out.println ("The difference between these two complex numbers is:");    this.sh=p1.sh-p2.sh;    This.xu=p1.xu-p2.xu; Print ();}    public void Outputfu () {System.out.println ("The value of the complex number is:"); Print ();}    public void print () {if (this.xu>0) {System.out.println (this.sh+ "+" +this.xu+ "I");    }else if (this.xu<0) {System.out.println (this.sh+ "" +this.xu+ "I");    }else{System.out.println (this.sh); }}}

C. Test code:

Package Exp1;import Java.util.scanner;public class Mycomplex {static int r;static int I;private double m;private double n;    public static int Getrealpart (int realpart) {r = Realpart; return r;}    public static int Getimaginepart (int imaginepart) {i = Imaginepart; return i;}    Public Mycomplex (double m, double n) {this.m = m; THIS.N = n;} Public Mycomplex Add (Mycomplex c) {return new Mycomplex (M + c.m, n + C.N);} Public Mycomplex minus (Mycomplex c) {return new Mycomplex (M-C.M, N-C.N);} Public Mycomplex Multiply (Mycomplex c) {return new Mycomplex (M * c.m-n * C.N, M * C.N + n * c.m);}    Public String toString () {String rtr_str = "";    if (n > 0) rtr_str = "(" + M + "+" + N + "I" + ")";    if (n = = 0) Rtr_str = "(" + M + ")";    if (n < 0) Rtr_str = "(" + M + n + "I" + ")"; return rtr_str;}}
(v) UML

UML diagrams can be translated into Java code

Psp
Steps Time Consuming percentage
Demand analysis 30min 16.7%
Design 60min 33.3%
Code implementation 45min 25%
Test 15min 8.3%
Analysis Summary 30min 16.7%

20145331 2nd Experimental Report on Java programming

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.