Design idea of supermarket cashier system

Source: Internet
Author: User
Tags constant list of attributes socket thread class

design and analysis of supermarket cashier system

First, the overall structure of the system

Figure 1

As can be seen from Figure 1, the system framework is very clear, the user login, according to the different user rights, corresponding to different operating methods, the operation of the object as a commodity.

However, the system requires the use of C/s framework structure to design.

Introduction of C/S framework:

c/S structure, known as the client and server structure.

The basic principle of C/s structure is to decompose the computer application task into many sub-tasks, which is done by multiple computers, that is, the principle of "function distribution" is adopted. The client finishes data processing, data representation and user interface functions, and the server completes the core functions of DBMS (Database management system). This kind of customer requests the service, the server provides the service the processing way is one kind of new computer application pattern.

Client and server are often located on two separate computers, the client program's task is to submit the user's requirements to the server program, and then the results returned by the server program are displayed to the user in a specific form The task of the server program is to receive the service request from the client, process it accordingly, and return the result to the client program.

In view of the characteristics of supermarket cashier system, this system does not involve multiple clients, and does not require thread synchronization.

Second, the Code design framework

Because of the use of the C/S framework design program, there are fixed design steps:

1. Design of the project package:

Figure 2

Client Package: mainly by the interface class of clients and client business class, the client operation class is the client Main method class, mainly responsible for guiding the user operation, providing the system interface information prompt operation, including: Initialize login view, inventory management view and Cashier management view The client business class mainly includes methods to process client requests and package the client requests to the server and some auxiliary action methods. The method for handling the inventory administrator request is: Merchandise storage, merchandise out of the library, new products, query all goods and by the number of products; The Cashier request method is: Scan the item, modify the purchase quantity and checkout.

Entity Package: mainly consists of the entities involved in the system, according to the operation view can be identified as user classes and commodity classes.

Figure 3 User Information

Figure 4 Product Information

Server Package: mainly consists of the server main process class (thread Class) and server (data processing) business class, the server main process class is also the Main method class, mainly responsible for receiving client requests, and according to the request flag information to assign the appropriate action, and then send the processing data to the client The server data processing business class mainly consists of the method of processing client request and the commodity information database.

Util Package:

The util package is a utility package that mainly includes some tool classes in the project, including data processing classes (encryption, decryption, data conversion, special file manipulation and data packaging), and constant classes.

This project mainly includes data packing class, constant class and Proprties file operation class.

sys.properties File:

Properties file is a text file, the properties file has two syntax, one is a comment, one is a property configuration; Note: Precede with the # number; Property configuration: Writes a property's configuration information as a "key = value".

The properties class itself represents the operation of a map structure, and the properties file itself represents a collection of "key-value pairs", so the properties class belongs to the collection container's family, and a container for properties should be created before use. is to create a default properties object without parameters, and add a "key-value pair" to it in a different way.

The role of sys.properties in this project is primarily to configure Server information: Host name and port number.

2, project design knowledge points

This project mainly designs key knowledge points: Classes and objects, encapsulation, inheritance, exceptions, collections and generics, input/output, multithreading and network programming.

3. Code Writing Ideas

1) Create a project

2) Create Java Package: Client package, Server package, Entity package, utility kit.

3) Create configuration file:. properties file or. xml file.

4) Create the class files in each Java package:

Client Package: Client interface class and client business class;

Server package: Server main Process Class (thread Class) and Server business class (data processing);

Physical package: Created according to the specific project situation;

Utility Kit:

ü Packet class: Key data for the interaction between client and server, including entity object and logical judgment mark;

ü Constant class: A State constant that requires common use between client and server, typically a business operation identifier and system information constant (correct, error state constant, configuration information constant).

ü Tool Class: General configuration file Operation class.

5) Write a project file (from simple to complex: a single function to all functional development).

6) Commissioning of the project.

Third, the specific Code analysis

1. sys.properties File Preparation

The main user of the file configures socket socket properties: hostname and port number, where the configuration information is:

Figure 5 SYS Information

2. Entity class writing

According to the entity package analysis, the goods class and the Users class.

Goods class:

Figure 6 Goods Class

Users Category:

Figure 7 The Users Class

NOTE: Because socket programming is involved, both entity classes need to be serialized.

3. Utility Kit Class Authoring

1) Packet class (Datas Class):

Because the project is a supermarket cash register system, according to the project effect diagram, the main design object is: Commodity object (goods), user object; To facilitate the operation of commodity information, create a collection of goods, but also because of the inventory management and collection of two classes, and then create a collection of inventory and purchase of goods set And because of the involvement of client and server-side business request operations, a business Operation identity variable is created: flag. The specific contents are as follows:

Figure 8 Datas Class

Figure 9 Application requirements for inventory item collection

Figure 10 Purchase Product collection application requirements

Note: Because of the socket programming involved, the Datas class needs to be serialized.

2) Tool Class (Tools class file):

Tools files are primarily used to manipulate the Sys.properties file, before the Sys.properties file operation, you first need to load the source file (in view of the load operation particularity (advance operation), using a static block to encapsulate), before you can read the value of the key in the Sys.properties file.

This class is primarily used to read the socket parameter information (host,port).

Figure 11

Propertis method: Void Load (InputStream instream) reads the list of attributes (key and element pairs) from the input stream.

ClassLoader class: The class loader is the object that is responsible for loading classes.

InputStream getResourceAsStream (String name): Returns the input stream that reads the specified resource.

3) Constant class:

From the code to write the thinking analysis: The constant class list is mainly composed of the following departments: System configuration constants, System Information feedback constants, system operation constants, administrator operation constants, cashier operation constants.

Figure 12 List of constants

Note: Specific constant parameters can be added or truncated in specific programming.

4. Client Class Authoring

1) Client Operation interface class:

The Client interface class mainly completes the following tasks: (1) User login (2) User action

There are two options for user login: Administrator and cashier; user actions are also initiated by the Administrator and cashier respectively.

Figure 13 Administrator Login Success View

Figure 14 Cashier Login Success View

Since there are only two options for login, it is quicker to write with If-else. The specific code screenshot is as follows:

Figure 15 Login Operation code

The administrator operation and the salesman operation Choice is more, therefore uses the switch to achieve more suitable, the specific code screenshot is as follows:

Figure 16 Administrator action Code

Figure 17 Cashier Operation code

Main () method: In principle Main () the more simple the better, the specific code screenshot is as follows:

Figure Main () method code

Note: Code written as above module to write (login method, Administrator action method, cashier method), the implementation of the method depends on the client business class, this class is mainly responsible for the view of the guidance and display, can be divided into modules to write and debug, follow the principle of simple into the complex.

2) Client Business class:

The client class method is written primarily to meet the needs of the Client interface class and need to implement the server-side information interaction (through socket programming), so the specific code includes the processing of login information (method), the administrator view of the Business operations Processing (method), the cashier view of the Business operations Processing (method) , as well as the logical operation methods required for the business operation process. The specific code screenshot is as follows:

Figure 19 Client Business method

Because of the need to use socket programming to achieve client-server data communication, the socket initialization and socket shutdown operations are required. The specific code is as follows:

Initialize and close operations of the socket

Note: The debugging of the client business class should be done after the framework of the server class has been set up (the basic communication answer operation can be completed).

Client programming key points:

The client sends the data writing principle, through the Datas class the attribute parameter as the carrier, namely to the customer information, the commodity information and the business Operation constant identifier carries on the data packing, all will need to send the key information encapsulates in the Datas object, then sends this object to the server, the specific code screenshot follows:

Figure 21 Key information of commodity storage Datas package Send code

Simultaneously reads the datas data returned by the server side, extracts the required information for processing and judgment, including the status constant information (success or error), the specific code screenshot is as follows:

Figure 22 reading the server returns data and processing

5. Server Class Authoring

1) Server main process class:

The server main process class is also the thread class, and this thread class is implemented by inheriting the thread parent class.

The run () method is mainly responsible for reading the data sent by the client, extracting the business Operation constant identification, and then the corresponding operation, the specific data processing relies on the server business class to implement, and then in the processing of data packaging (Datas) sent to the client, the specific code screenshot is as follows:

Figure 23 reading the client data and manipulating the code accordingly

Figure 24 Package the processed data to the client action code

2) Server Business class:

The server business class mainly consists of two parts: basic data: User information (Administrator and Cashier's account, password-rom type), inventory commodity information (ROM type), purchase commodity information (RAM type), handle the data processing method of client request. The underlying data is then available to the database to save processing.

ROM-type data initialization is implemented using a static block, executed once, and executed first. The specific code screenshot is as follows:

Figure 25 System Base data code

Data processing methods are parameter methods, because the processing information is sent to the client, and the specific return data type is determined by the specific business operation. The specific code screenshot is as follows:

Figure 26 Server Business processing method code

Note: When the client and the server, the basic framework of the client and server can be set up, debugging the basic functions and then do the subsequent code expansion and debugging.

Problem Point Collection:

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.