Java 6.22 Exercise-----Simulation of Logistics Express System Programming

Program design of logistics express system
Analysis of ideas:
1. First create a vehicle class, define this class as an abstract class, including the attributes of vehicle number, model, and consignor's name, and define an abstract transportation method.
2. After transportation, maintain the vehicle, define the maintenance interface, and realize the maintenance function.
3. Define a transport vehicle class, inherit the vehicle class and implement the maintenance interface.
4. Start to transport the goods. For the method of cargo transportation and delivery process, define the courier task class, including the courier order number, cargo weight attribute
5, cargo transportation process, locate the transport vehicle to track the location information of the cargo, because there are many devices that realize the positioning function, define a GPS Interface, defining the location class (phone class) that implements the interface

The implementation code is as follows:

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
operation result:

insert image description here

Analysis and summary:
comprehensively examine the application of inheritance, polymorphism, and encapsulation functions, as well as important knowledge points of interfaces.
Review of polymorphism:
public class Master { //Create a master class public void feed(Animal a, Food f){ //This parameter defines the parent class object, but when passing parameters, it is the subclass of the parent class The object, the parent class can still recognize, and call the methods in the subclass respectively, this is polymorphism //polymorphism is a variety of reference forms of the parent class, which can be understood as calling the definition in different subclasses through pointers to the parent class The methods, such as the a of the parent class defined above, can point to cats and dogs of the subclass a.eat(); f.showName(); } }







insert image description here
Here is a polymorphic implementation of the interface.

Note: When using member variables, combine the actual setting permissions. If you want to use it, add the set get method for other classes to use.

Notes on abstract classes and abstract methods:
1. Abstract classes cannot be instantiated
2. Abstract classes do not necessarily have to contain abstract methods, they can be absent
3. Once a class contains abstract methods, the class must be declared as an abstract class
4. Abstract A class cannot have a subject.
5. If a subclass is defined as an abstract class, it does not need to implement the abstract method of the parent class.
6. A subclass can only inherit one parent class. Similarly, a subclass can only inherit one abstract class

Interface Content Review
An interface is a more abstract abstract class.
The difference with an abstract class:
a subclass can only inherit one abstract class, and a class can implement multiple interfaces.
Features: Using the interface keyword, an interface is a class that is more abstract than an abstract class, and it cannot be instantiated. Subclasses are required to enforce implementation of abstract methods.

insert image description here

Guess you like

Origin blog.csdn.net/wuwndj/article/details/106908315