当前位置:网站首页>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;
}
}
}
边栏推荐
- Go从入门到实战——所有任务完成(笔记)
- Modify large online games through CE modifier
- Data platform scheduling upgrade and transformation | operation practice from Azkaban smooth transition to Apache dolphin scheduler
- 农产品期货怎么做怎么开户,期货开户手续费多少,找谁能优惠手续费?
- Icml2022 | scalable depth Gaussian Markov random field
- Prospects for enterprise digitalization (38/100)
- Go from entry to practice - dependency management (notes)
- Go from introduction to actual combat - context and task cancellation (notes)
- Squid proxy server
- 关于异常处理的知识整理
猜你喜欢
Squid proxy server
划重点!国产电脑上安装字体小技巧
Go from introduction to practice -- coordination mechanism (note)
Go from entry to practice - multiple selection and timeout control (notes)
SQL必需掌握的100个重要知识点:过滤数据
Codeforces Round #717 (Div. 2)
Go from introduction to actual combat - panic and recover (notes)
Release of global Unicorn list in 2021: the full list of 301 Unicorn enterprises in China is coming!
mysql使用笔记一
释放开源数据库创新力量 | 【甘肃】openGauss Meetup圆满结束
随机推荐
送你12个常用函数公式,用过的都说好
鲜为人知的mysql导入数据
MySQL performance optimization index function, hidden, prefix, hash index usage (2)
Golang 使用正则来匹配出子字符串函数
Day8 ---- 云资讯项目介绍与创建
创建对象时JVM内存结构
MySQL usage notes 1
squid代理服務器
非常全面的DolphinScheduler(海豚调度)安装使用文档
Love math experiment | phase 9 - intelligent health diagnosis using machine learning method
100 important knowledge points that SQL must master: retrieving data
SQL必需掌握的100个重要知识点:排序检索数据
Go from introduction to actual combat - package (notes)
How to do a good job of gateway high availability protection in the big promotion scenario
如何将队列里面的内容没秒钟执行一次优先级
GFS分布式文件系统
Experience Navicat premium 16, unlimited reset, 14 day trial method (with source code)
Use the storcli tool to configure raid. Just collect this article
抖音的兴趣电商已经碰到流量天花板?
覆盖接入2w+交通监测设备,EMQ 为深圳市打造交通全要素数字化新引擎