Courier
public class Courier extends Person {
private String courisrId;
public Courier(){
}
public Courier(String courisrId ,String pwd){
super.setPwd(pwd);
this.courisrId = courisrId;
}
public Courier(String courisrId, String name, String sex ,int age , String pwd){
super(name,age,pwd,sex);
this.courisrId = courisrId;
}
public String getCourisrId(){
return courisrId;
}
public void setCourisrId(String courisrId){
this.courisrId= courisrId;
}
@Override
public String toString(){
return "Courier{" +
"courierId='" + courisrId +'\'' +
", name='" + getName() +'\''+
", age='" + getAge() +'\''+
", pwd=" + getPwd() +'\'' +
", sex='" + getSex() +'\'' +
'}';
}
}
Person
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;
}
}
LoginService
public class LoginService {
private Scanner sc = null;
public LoginService(Scanner scanner) {
this.sc = scanner;
}
/**
* 用户注册
*/
public void register(Scanner sc) {
System.out.println("请输入用户编码:");
String clientId = sc.next();
System.out.println("请输入用户的密码:");
String pwd = sc.next();
System.out.println("请输入用户名");
String name = sc.next();
System.out.println("请输入年龄:");
int age = sc.nextInt();
System.out.println("请输入性别:");
String sex = sc.next();
System.out.println("请输入手机号码:");
String phone = sc.next();
Customer customer = Customer.builder().setCustomerId(clientId).setCustomerId(pwd);
customer.setName(name);
customer.setAge(age);
customer.setPhone(phone);
customer.setSex(sex);
// 把上面的对象保存到数组
// CustomerData.save(customer);
}
}
CourierData
public class CourierData {
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< CUSTOMERDATA.length; i++){
if (null == CUSTOMERDATA[i]){
CUSTOMERDATA[i] =customer;
COUNT++;
return;
}
}
}
// 从数组中查询用户的信息
public static Customer get(String customerId , String pwd){
for (Customer c : CUSTOMERDATA){
if(c.getCustomerId().equals(customerId) && c.getPwd().equals(pwd)){
return c;
}
}
return null;
}
// 只根据id查询用户
public static Customer get(String customerId){
for (Customer c : CUSTOMERDATA){
if (customerId.equals(c.getCustomerId())){
return c;
}
}
return null;
}
}