Assignment 04 - Object Oriented Design and Inheritance

1. This week's learning summary

1.1 Write down the key words of knowledge points that you think are more important in this week's study
1.2 Try to use the mind map to organize these key words. Note: Mind maps generally do not require too many words.
1.3 Optional: Summarize other lesson content using conventional methods.

2. Written work

1. Object-Oriented Design (big assignment 1 - this assignment will serve as the basis for other assignments in the future, please be sure to complete it)

1.1 Storytelling: Tell a story about you shopping in an online store or learning from a class blog. Use Markdown's bold mark to mark out key nouns , and use 语句块标记to mark out key verbs . Storytelling example: Please refer to How to Draw a Class Diagram in UML Class Diagram 1.2 Key Check: Find out each class included in the system and its attributes, methods , and the relationship between classes , and draw the corresponding UML class diagram . As shown in the following figure: Please refer to the reference materials for class diagram drawing: Summary of several relationships in UML class diagram Tip 1: When drawing a class diagram, pay attention to the shape of the arrow. For example, inheritance uses a solid hollow arrow from a subclass to a superclass. The implementation uses the dashed hollow arrow to point from the implementing class to the interface. Common relationships that need to be expressed are: inheritance (solid line with hollow triangle arrows), implementation (dotted line with hollow triangle arrows), and dependencies (dotted line with arrows). Tip 2: Do not make meaningless turns in the line segments in the class diagram. Tip 3:





The class design does not necessarily have to reflect the inheritance relationship, as long as the system can be described completely. Don't think too much when designing at the beginning, don't appear too many classes, only appear the necessary classes and complete the minimum functions. For the shopping mall shopping system, it is recommended to only use the shopping cart module.

1.3 Give the codes of the key classes in the system (at least the codes of shopping cart and commodity). Optional: Try to implement and run the system, and paste the screenshots and key codes of the operation. In the future, it will gradually improve and expand into a complete object-oriented system on this basis. Cooperative completion: a group of 2-3 people.
Optional: Team collaboration can use git and code cloud. Create a new project in the code cloud. All team members should have submission records under the item in the code cloud. Take a screenshot of your commit history.
References:

Use Processon to draw
object-oriented case-borrower's name and address.zip
directly from the code to generate class diagrams Eclipse plug-in-ModelGoon

2. ManagerTest.zip code analysis (inheritance, polymorphism)

Analyze the code in ManagerTest.zip and answer several questions:
2.1 Briefly describe the inheritance relationship shown in the code. Which are public methods and which are subclass-specific properties and methods?
2.2 In line 26 of the file e.getSalary(), is it calling the getSalary method of the Manager class or the Employee class?
2.3 ManagerThe constructor superof the class implements code reuse by calling the constructor of the parent class. What is the benefit of this? Why not copy-paste the relevant code from the parent class constructor into the Manager's constructor, doesn't it seem more intuitive?

3. toString and equals in Object class

3.1 Write Fruitclasses, properties String name. If you override it toString()方法, will the code of the toString method in its parent class be gone? Write the method of Fruit toString(), in which the string obtained by calling the method of the parent class is spliced toString​​with its own unique attributes name, how to write? (Screenshot code: student number and name appear)
3.2 FruitWrite an equals method for the class to override the corresponding method of the parent class. The function is to return when the names of the two Fruit objects are the same (ignoring case) true. (Screenshot code: student ID and name appear)
3.3 After completing 3.2, use to ArrayList<Fruit> fruitListstore multiple fruits. When adding, it is required that if the fruit object to be added already exists in the fruitList, it will not be added, and if it does not exist, it will be added. Write relevant test code (screenshots should include code and running results, and your student ID and name should appear in the running results). And take a screenshot of containsthe key code in the ArrayList to analyze how it is related to the equalsmethod?
Tip: Use the contains method of ArrayList directly to determine whether the object exists.
3.4 Combined with the PTA function question Object , answer: Why can an array of Object type be used to store any type of object?

4. Experiment summary: (no own summary, all score 0)

4.1 PTA programming questions (shape-inheritance). And answer: In completing this question, you used the polymorphism feature, what benefits do you think this feature brings to the completion of the question.
4.2 PTA programming questions (covered). And answer: What do you need to pay attention to when writing the equals method? Use reflexivity, symmetry, transitivity, consistency, and non-nullness to verify that the equals method you wrote is correct through code.
Reference materials: 1. How to rewrite the equals method correctly
2. General conventions to be followed when overloading the equals method--reflexivity, symmetry, transitivity, consistency, non-empty
4.3 Program fill-in-the-blank, function questions (1-3 ). You need to write your own summary, and screenshot code is prohibited.

Optional: 5. Code reading: EqualsTest.java (equals and hashCode)

5.1 Add Chinese comments and screenshots to each line Employeeof the function of the class . 5.2 Add Chinese comments and screenshots to each line of the function of the class . Answer, what should I pay attention to when writing the equals method of the subclass? 5.3 View the source code. And answer, what do I need to pay attention to when writing the method of the subclass ? 5.4 Add Chinese comments to the source code. Combined with the knowledge in the data structure, what do you think is the use of the hashCode method in each class? Reference link:equals
Managerequals
ManagerhashCodehashCode
EmployeehashCode

EqualsTest.zip

3. Code Cloud and PTA

Topic set: [jmu-Java-03-Object-Oriented 1-Basic-Encapsulation Inheritance]

3.1. Code cloud code submission record

  • In the code cloud project, select "Statistics-Commits History-Set Time Period", then search and take a screenshot

3.2 Screenshot PTA Question Set Completion Chart

Completion of this week (shape-inheritance, overlay)
requires two plots (1. rank. 2. list of PTA submissions)

3.3 Count the amount of code completed this week

The weekly code statistics need to be merged into one table.
The table format is as follows:

Week total code add code total number of files Number of new files
1 200 200 3 3
2 500 300 7 4
3 600 100 8 1

Other (do not do):

1. Application of annotations

Annotate previously written classes and methods with class annotations and method annotations and view related annotations in Eclipse by hovering over them. (screenshot)

3. Object class

3.1 Write Fruitclasses, properties String name. Use System.out.println(new Fruit());what method of Fruit is called? Where does the code for this method come from? What does this code accomplish?

6. Experiment summary:

5.3 PTA programming questions (inheritance coverage comprehensive exercises). And answer: Collections.sortWhat are the prerequisites for sorting an array of reference types?

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325129432&siteId=291194637