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ǒng)\t\t");
? ? ? System.out.println("1 用戶注冊");
? ? ? System.out.println("2 登錄系統(tǒng)");
? ? ? System.out.println("3 商品查看冊");
? ? ? System.out.println("4 退出系統(tǒng)");
? ? ? System.out.println("請輸入:");
? ? ? int funNo = scanner.nextInt();
? ? ? switch (funNo){
? ? ? ? ? case 1:
? ? ? ? ? ? ? //用戶注冊
? ? ? ? ? ? ? break;
? ? ? ? ? case 2:
? ? ? ? ? ? ? //登錄系統(tǒng)
? ? ? ? ? ? ? break;
? ? ? ? ? case 3:
? ? ? ? ? ? //商品查看
? ? ? ? ? ? break;
? ? ? ? ? case 4:
? ? ? ? ? ? ? //退出系統(tǒng)
? ? ? ? ? default:
? ? ? ? ? ? ? scanner.close();? ? ? ? ? ? //關(guān)閉掃描器資源
? ? ? ? ? ? ? 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("請輸入手機(jī)號:");
? ? ? ? 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只能出現(xiàn)方法第一行
? ? this.courierId = courierId;
}
? ? @Override
? ? public String toString() {
? ? ? ? return "Courier{" +
? ? ? ? ? ? ? ? "courierId='" + courierId + '\'' +
? ? ? ? ? ? ? ? ", name='" + getName() + '\'' +
? ? ? ? ? ? ? ? ", age='" + getAge() + '\'' +
? ? ? ? ? ? ? ? ", pwd='" + getPwd() + '\'' +
? ? ? ? ? ? ? ? ", sex='" + getSex() + '\'' +
? ? ? ? ? ? ? ? '}';
? ? }
}
public? Customer(){
? ? }
? ? //構(gòu)建器? 用來構(gòu)建一個對象
? ? 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;? ? //一共能存儲的用戶數(shù)
? ? private? static? int COUNT = 0;? ? //已經(jīng)存儲的用戶
? ? private? static Customer[]CUSTOMERDATA = new? Customer[SIZE];
? ? public? static? void? save(Customer customer){
? ? ? ? if (COUNT ==SIZE){? //數(shù)組滿了,擴(kuò)容為原來的二倍
? ? ? ? ? CUSTOMERDATA =? Arrays.copyOf(CUSTOMERDATA,SIZE*2);
? ? ? ? ? ? SIZE *=2;
? ? ? ? }
? ? ? ? for (int i = 0; i <CUSTOMERDATA.length ; i++) {
? ? ? ? ? ? if (null==CUSTOMERDATA[i]){
? ? ? ? ? ? ? ? CUSTOMERDATA[i] = customer;
? ? ? ? ? ? ? ? COUNT++;
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? //從數(shù)組中查詢用戶的信息
public? static Customer get(String customerId,String pwd){
? ? ? ? for (Customer customer: CUSTOMERDATA){
? ? ? ? ? ? if (customer.getCustomerId().equals(customerId) && customer.getPwd().equals(pwd)){
? ? ? ? ? ? ? ? return customer;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return null;
}
? //只根據(jù)id查詢用戶
public? static Customer get(String customerId){
? ? ? ? for (Customer customer:CUSTOMERDATA){
? ? ? ? ? ? if (customerId.equals((customer.getCustomerId()))){
? ? ? ? ? ? ? ? return customer;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return null;
}
}