当前位置:网站首页>Express e stack - small items in array
Express e stack - small items in array
2022-06-27 21:39:00 【continueLR】
Catalog
1. Role switching ( Couriers and ordinary users
Reasons for stepping on the pit :
Today's mission , Is to complete the express delivery E Stack ( Console easy version ) System . Variable passed , Process control , Learning of three parts of array , Let's work on a small project Consolidate these skills ! Don't underestimate what we learned before , Now we can get through this Some knowledge points to complete a simple version , Express based on console version E Stack , In the process of completion , Big Home should master the application of knowledge , Also learn the business logic , For greater express delivery after us E Prepare for stack system implementation .
Function is introduced :
1. Role switching ( Couriers and ordinary users

Courier function : Deposit Express , Delete express , Modify Express , Check out all the couriers
Ordinary user functions : Pick up express
2. Deposit Express

3. Delete express

4. Modify Express

5. Check out all the couriers

6. Pick up express

Ideas :
1: The array can represent the express cabinet , Use traversal to find express , Create objects , It is equivalent to the access of an express cabinet .
2:switch The cycle is suitable for the project presented one by one , In this project for It is more suitable for the main loop
3: Properties of array subscripts , from 0 Subscript start , No matter how many subscripts there are =-1, utilize -1 To determine whether an object is created
Reasons for stepping on the pit :
I do not know! contentEquals() Methods and Math.random() Method
Code implementation
package com.java.bean;
import java.util.Scanner;
public class ExpressArray {
public static void main(String[] args) {// Main method
Scanner scan = new Scanner(System.in);// The console receives data
String[] OrderId = new String[10];// courier number
String[] comName = new String[10];// Express name
int[] codeGet = new int[10];// Pick up code
System.out.println(" Welcome to the express cabinet of new vocational course ======");
System.out.println(" Please enter your identity information : 1. Courier 2. user ");
int num = scan.nextInt();// Receive integer type num1
switch (num) {
case 1:// Courier
System.out.println(" Please select : 1. Deposit Express 2. Delete express 3. Modify the courier information 4. View all express information ");
int num2 = scan.nextInt();// Receive integer type num2
switch (num2) {
case 1: // Deposit Express
int index1 = -1;// Given index1 One -1 Value , Used to judge whether the express cabinet is full , Loop traversal
for (int i = 0; i < OrderId.length; i++) {// Traversal array ,String The initial value of the type array is null
if (OrderId[i] == null) {// Check for null, If the object is saved, it is not null 了
index1 = i;// If there is null, Just assign it to index
break;// The end of the statement
}
}
if (index1 == -1) {// If index still -1 explain i Not given index assignment , Prove that all arrays are not null
System.out.println(" The express cabinet is full , Unable to continue depositing ");
} else {// Since you can walk to else, It indicates that the array is null, After a long time, the index of this array can be re assigned
System.out.println(" Please input the express number :");
String number1 = scan.next();// Input number1
OrderId[index1] = number1;// Will array OrderId[index1] Subscript assignment number1
System.out.println(" Please enter the courier company :");
String company = scan.next();// Input company
comName[index1] = company;// take comName[index1] Subscript assignment company
int code = (int) (Math.random() * 100000) + 100000;//int Type of pick-up code code Assign one 1000 Number within
codeGet[index1] = code;// above code It's a random six digit number , hold codeGet[index1] The subscript is assigned to him
System.out.println(" The express has been deposited in , The pick-up code is " + code);// Output pick-up code
break;// The end of the statement
}
break;
case 2: {// Delete express
System.out.println(" Please enter the courier number you want to delete ");
String number2 = scan.next();// Receive one string Data of type ,number2
int index2 = -1;// The same is given first index2 Subscript a -1 Value , Look for the heel number2 The same object
for (int i = 0; i < OrderId.length; i++) {// After traversing the array , If there is any number The same object assigns it to index Subscript
if ((number2).equals(OrderId[i])) {// If i The delivery order number of the subscript is followed by number2 same , Then find the target
index2 = i;// Finding the target will i Assign a value to index
break;// end if sentence
}
}
if (index2 == -1) {// If index still -1 explain i Not given index2 assignment , Prove that all subscript array data are not number2
System.out.println(" The express order No. does not exist ");
} else {// The program comes to this , explain index No -1,number2 Already found .
OrderId[index2] = null;// but index The three arrays under the subscript are all initial values , Express has been deleted
comName[index2] = null;
codeGet[index2] = 0;
System.out.println(" The express delivery order number has been deleted ");
}
break;
}
case 3: {// Modify Express
System.out.println(" Please enter the courier number you want to modify ");
String number3 = scan.next();// Receive one string Data of type ,number2
int index3 = -1;// The same is given first index3 Subscript a -1 Value , Look for the heel number3 The same object
for (int i = 0; i < OrderId.length; i++) {
if ((number3).contentEquals(OrderId[i])) {
index3 = i;
break;
}
if (index3 == -1) {// If index3 still -1 explain i Not given index3 assignment , Prove that all subscript array data are not number3
System.out.println(" The express order No. does not exist ");
} else {// The program comes to this , explain index3 No -1,number3 Already found
System.out.println(" Please enter a new courier number ");
String number4 = scan.next();// Receive one string Data of type ,number4
OrderId[index3] = number4;// Will array OrderId[index3] Subscript assignment number4
System.out.println(" Please enter a new express company ");
String newCompany = scan.next();// Receive one string Data of type ,newCompan
comName[index3] = scan.next();// take comName[index3] Subscript assignment company
int newCodeGet = (int) (Math.random() * 100000) + 100000;// Random number creation
codeGet[index3] = newCodeGet;// Assign a six digit random number to the new pickup code newCodeGet
}
break;
}
}
case 4: {// Check out all the couriers
int index4 = -1; // Judge whether the express cabinet is completely empty
for (int i = 0; i < OrderId.length; i++) {// Traversal array
if (OrderId[i] != null) {// As long as there is a subscript
index4 = 0;// to index assignment 0
break;// The end of the statement
}
}
if (index4 == -1) {// If index4 still -1 explain i Not given index4 assignment , Prove that all subscript array data are null
System.out.println(" The express cabinet is empty , No express delivery ");
} else {// The program comes to this , explain index4 No -1,index4 Assigned value 0
System.out.println(" All courier information is as follows :");
System.out.println(" courier number \t Corporate name \t Pick up code ");
for (int i = 0; i < OrderId.length; i++) {// Traverse the array and output the new pickup code information
System.out.println(OrderId[i] + "\t" + comName[i] + "\t" + codeGet[i]);
}
}
}
break;// End of cycle
}
case 2:// user
System.out.println(" Please enter the pickup code ");
int codeUser = scan.nextInt();// Receive one int Data of type ,codeUser
int index = -1;// Match the pick-up code
for (int i = 0; i < OrderId.length; i++) {
if (codeGet[i] != 0 && codeGet[i] == codeUser) {
index = i;
break;
}
}
if (index == -1) {// If index still -1 explain i Not given index4 assignment , That is, there is no match to
System.out.println(" The express was not found ");
} else {// The program comes to this , Description has been matched
OrderId[index] = null;// The pickup code is null, That was taken away
System.out.println(" You have taken pieces successfully ");
}
break;
}
}
}
边栏推荐
猜你喜欢

MYSQL 性能优化 index 函数,隐藏,前缀,hash 索引 使用方法(2)

Educational Codeforces Round 108 (Rated for Div. 2)

Tiktok's interest in e-commerce has hit the traffic ceiling?

Oracle的CTAS能不能将约束等属性带到新表?

快递e栈——数组篇小型项目

100 important knowledge points that SQL must master: sorting and retrieving data

Go从入门到实战——仅执行一次(笔记)

MySQL performance optimization index function, hidden, prefix, hash index usage (2)

Go from entry to practice -- CSP concurrency mechanism (note)

今晚战码先锋润和赛道第2期直播丨如何参与OpenHarmony代码贡献
随机推荐
Yu Wenwen, Hu Xia and other stars take you to play with the party. Pipi app ignites your summer
Serveur mandataire SQUID
Null pointer exception
Go from entry to practice - multiple selection and timeout control (notes)
快递e栈——数组篇小型项目
富文本 考试 填空题
通过CE修改器修改大型网络游戏
Go从入门到实战——错误机制(笔记)
100 important knowledge points that SQL must master: filtering data
BTC and eth recapture the lost land! Leading the market recovery? Encryption will enter the "ice age"!
Animal breeding production virtual simulation teaching system | Sinovel interactive
银河麒麟系统局域网文件共享教程
MySQL usage notes 1
Flask----应用案例
Go from introduction to practice - Interface (notes)
Squid proxy server
linux下安装oracle11g 静默安装教程
MySQL performance optimization index function, hidden, prefix, hash index usage (2)
今晚战码先锋润和赛道第2期直播丨如何参与OpenHarmony代码贡献
Codeforces Global Round 14