简单的仓库管理系统的实现:学校项目实验
- 这个小项目做的也是勉强实现功能,但感觉代码有一部分太过冗余,比如修改产品可以用set方法,而我相当于直接删掉了再重新赋值商品属性,只是保留原来的产品id而已
package o0917;
public class Product {
String productName;
int productNums;
double productPrice;
int productStoreNum;
int productIdtifies;
@Override
public String toString() {
return "Product{" +
"productName='" + productName + '\'' +
", productNums=" + productNums +
", productPrice=" + productPrice +
", productStoreNum=" + productStoreNum +
", productIdtifies=" + productIdtifies +
'}';
}
public Product(){
}
public Product(int productIdtifies,String productName, int productNums, double productPrice, int productStoreNum) {
this.productIdtifies = productIdtifies;
this.productName = productName;
this.productNums = productNums;
this.productPrice = productPrice;
this.productStoreNum = productStoreNum;
}
public int getProductIdtifies() {
return productIdtifies;
}
}
package o0917;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class General {
public static void main(String[] args) {
General general = new General();
while (true){
Scanner scanner = new Scanner(System.in);
System.out.print("请输入功能编号:");
int number = scanner.nextInt();
if (number == 1){
general.increment();
}else if (number == 2){
general.alterProduct();
}else if (number == 3){
general.deleteProduct();
}else if (number == 4){
general.showProduct();
}else if (number == 0){
System.out.println("Bye~");
return;
}else{
System.out.println("编号有误请重新输入");
}
}
}
List<Product> list = new ArrayList<>();
int tmpProductIdtifies = 1;
public void showProduct() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入产品id:");
int p_id = scanner.nextInt();
for(int i = 0;i < list.size(); i ++){
Product tmp = list.get(i);
if (tmp.getProductIdtifies() == p_id){
System.out.println(tmp.toString());
}
}
}
public void increment() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入产品名称:");
String p_name = scanner.nextLine();
System.out.print("请输入产品数量:");
int p_nums = scanner.nextInt();
System.out.print("请输入产品价格:");
double p_price = scanner.nextDouble();
System.out.print("请输入产品货柜:");
int p_store = scanner.nextInt();
list.add(new Product(tmpProductIdtifies++,p_name,p_nums,p_price,p_store));
System.out.println("添加成功");
}
public void deleteProduct() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入产品id:");
int p_id = scanner.nextInt();
for(int i = 0;i < list.size(); i ++){
Product tmp = list.get(i);
if (tmp.getProductIdtifies() == p_id){
list.remove(tmp);
}
}
System.out.println("删除成功");
}
public void alterProduct() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入产品id:");
int p_id = scanner.nextInt();
for(int i = 0;i < list.size(); i ++){
Product tmp = list.get(i);
if (tmp.getProductIdtifies() == p_id){
list.remove(tmp);
Scanner scanner2 = new Scanner(System.in);
System.out.print("请输入产品名称:");
String p_name = scanner2.nextLine();
System.out.print("请输入产品数量:");
int p_nums = scanner2.nextInt();
System.out.print("请输入产品价格:");
double p_price = scanner2.nextDouble();
System.out.print("请输入产品货柜:");
int p_store = scanner2.nextInt();
list.add(new Product(p_id,p_name,p_nums,p_price,p_store));
System.out.println("修改成功");
}
}
}
}
线程池 :实现线程管理/font>
package ksdxc.d27;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
public class d27 {
public static void main(String[] args) {
ExecutorService service = Executors.newFixedThreadPool(9);
service.execute(new MyThread());
service.execute(new MyThread());
service.execute(new MyThread());
service.shutdown();
}
}
class MyThread implements Runnable{
@Override
public void run() {
System.out.println(Thread.currentThread().getName());
}
}
TCP/IP协议与UDP协议:
- TCP:用户传输协议,可以看成打电话
连接,稳定 三次握手,四次挥手 客户端,服务端 效率低,传输完成,释放连接 - UDP:用户数据报协议,可以看成发短信
不连接,不稳定 不管有没有准备好,都可以发给你 DDOS:洪水攻击(饱和攻击) 想成定向导弹 - 分为四层:应用层,传输层,网络层,数据链路层
集合迭代器以及contains源码分析
package com.base.du667;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
public class du667 {
public static void main(String[] args) {
Collection collection = new ArrayList();
collection.add("jinahsua");
collection.add("huaerjirshi");
System.out.println(collection.size());
Collection collection1 = new ArrayList();
collection1.add("hua");
collection1.add("iva ");
collection1.add("rja");
collection1.add(new Object());
Iterator iterator = collection1.iterator();
while (iterator.hasNext()) {
Object object = iterator.next();
System.out.println(object);
}
ArrayList<Object> objects = new ArrayList<>();
String x01 = new String("h");
String x02 = new String("j");
String x03 = new String("j");
objects.add(x01);
objects.add(x02);
objects.add(x03);
System.out.println(objects.contains(x03));
}
}
package com.base.du674;
import java.util.ArrayList;
public class du674 {
public static void main(String[] args) {
ArrayList<Object> objects = new ArrayList<>();
User user1 = new User("cat");
User user2 = new User("cat");
objects.add(user1);
System.out.println(objects.contains(user2));
}
}
class User {
private String uname;
public User(){
}
public User(String uname) {
this.uname = uname;
}
}
class User {
private String uname;
public User(){
}
public User(String uname) {
this.uname = uname;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return Objects.equals(uname, user.uname);
}
}
集合中remove方法源码分析:
package com.base.du675;
import java.util.ArrayList;
public class du675 {
public static void main(String[] args) {
ArrayList<Object> objects = new ArrayList<>();
String bbww1 = new String("bbww");
String bbww2 = new String("bbww");
objects.add(bbww1);
System.out.println(objects.size());
objects.add(bbww2);
objects.remove(bbww2);
System.out.println(objects.size());
}
}
集合迭代器重新获取:
package com.base.du677;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
public class du677 {
public static void main(String[] args) {
Collection<Object> objects = new ArrayList<>();
objects.add(1024);
objects.add(1026);
objects.add(1030);
Iterator<Object> iterator = objects.iterator();
while (iterator.hasNext()){
Object object = iterator.next();
iterator.remove();
System.out.println(object);
}
}
System.out.println(objects.size());
}
|