飛鴿代碼

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;

}

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 課堂代碼public class Courier extends Person{private String co...
    陳龍閱讀 138評論 0 0
  • 引言 在Android應(yīng)用開發(fā)過程中,幾乎每個應(yīng)用都需要使用到數(shù)據(jù)庫,而直接使用系統(tǒng)的Sqlite存儲數(shù)據(jù)的話又不...
    horseLai閱讀 1,781評論 0 4
  • 首先創(chuàng)建一個數(shù)據(jù)庫,創(chuàng)建一個表 例如下圖這樣的 建立一個實體類 1.一般情況會與數(shù)據(jù)庫中表內(nèi)的數(shù)據(jù)類型一致 2. ...
    我叫路飛啊閱讀 5,514評論 0 0
  • 我是黑夜里大雨紛飛的人啊 1 “又到一年六月,有人笑有人哭,有人歡樂有人憂愁,有人驚喜有人失落,有的覺得收獲滿滿有...
    陌忘宇閱讀 8,900評論 28 54
  • 信任包括信任自己和信任他人 很多時候,很多事情,失敗、遺憾、錯過,源于不自信,不信任他人 覺得自己做不成,別人做不...
    吳氵晃閱讀 6,394評論 4 8

友情鏈接更多精彩內(nèi)容