日常笔记
飞鸽快递系统项目代码:
package edu.xcdq;
import java.util.Scanner;
public class Main { Scanner scanner = new Scanner(System.in);
public Main(){
}
public void menu(){
System.out.println("===========================");
System.out.println("\t\t欢迎使用快递系统\t\t");
System.out.println("1 用户注册");
System.out.println("2 登录系统");
System.out.println("3 商品查看册");
System.out.println("4 退出系统");
System.out.println("请输入:");
int funNo = scanner.nextInt();
switch (funNo){
case 1:
//用户注册
break;
case 2:
//登录系统
break;
case 3:
//商品查看
break;
case 4:
//退出系统
default:
scanner.close(); //关闭扫描器资源
System.exit(0); // 0 正常退出 非0 正常的中断退出
}
}
public static void main(String[] args) {
new Main().menu();
}
}
package edu.xcdq.service;
import edu.xcdq.beans.Customer;
import java.util.Scanner;
public class LoginService {
private Scanner scanner = null;
private LoginService(Scanner scanner) {
this.scanner = scanner;
}
//注册
public void register(Scanner scanner) {
System.out.println("请输入用户的编号:");
String clientId = scanner.next();
System.out.println("请输入用户名的密码:");
String pwd = scanner.next();
System.out.println("请输入用户名:");
String name = scanner.next();
System.out.println("请输入年龄:");
int age = scanner.nextInt();
System.out.println("请输入性别:");
String sex = scanner.next();
System.out.println("请输入手机号:");
String phone = scanner.next();
Customer customer = Customer.builder().setCustomerId(clientId).Pwd(pwd);
customer.setName(name);
customer.setPhone(phone);
customer.setSex(sex);
}
}
package edu.xcdq.beans;
public class Courier extends person{
private String courierId;
public Courier(){
}
public Courier(String courierId,String pwd){
super.setPwd(pwd);
this.courierId = courierId;
}
public Courier(String courierId,String name,String sex,int age,String pwd){
super(name,age,pwd,sex); //super只能出现方法第一行
this.courierId = courierId;
}
@Override
public String toString() {
return "Courier{" +
"courierId='" + courierId + '\'' +
", name='" + getName() + '\'' +
", age='" + getAge() + '\'' +
", pwd='" + getPwd() + '\'' +
", sex='" + getSex() + '\'' +
'}';
}
}
public Customer(){
}
//构建器 用来构建一个对象
public static Customer builder(){
return new Customer();
}
public String getCustomerId() {
return customerId;
}
public Customer setCustomerId(String customerId) {
this.customerId = customerId;
return this;
}
public Customer Pwd (String pwd) {
super.setPwd(pwd);
//this.pwd = pwd;
return this;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
@Override
public String toString() {
return "Customer{" +
"customerId='" + customerId + '\'' +
", phone='" + phone + '\'' +
", name='" + getName() + '\'' +
", age='" + getAge() + '\'' +
", pwd='" + getPwd() + '\'' +
", sex='" + getSex() + '\'' +
'}';
}
}
package edu.xcdq.beans;
public class person {
private String name;
private int age;
private String pwd;
private String sex;
public person(){
}
public person(String name,int age,String pwd,String sex){
this.name = name;
this.age = age;
this.pwd = pwd;
this.sex = sex;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
package edu.xcdq.tools;
import edu.xcdq.beans.Customer;
import java.util.Arrays;
public class CustomerData {
private static int SIZE = 10; //一共能存储的用户数
private static int COUNT = 0; //已经存储的用户
private static Customer[]CUSTOMERDATA = new Customer[SIZE];
public static void save(Customer customer){
if (COUNT ==SIZE){ //数组满了,扩容为原来的二倍
CUSTOMERDATA = Arrays.copyOf(CUSTOMERDATA,SIZE*2);
SIZE *=2;
}
for (int i = 0; i