课堂代码
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;
}
public String getCourierId() {
return courierId;
}
public void setCourierId(String courierId) {
this.courierId = courierId;
}
@Override
public String toString(){
return "Courier{" +
"courierId='" + courierId + '\'' +
"name='" + getName() + '\''+
"age='" + getAge() + '\''+
"pwd='" + getPwd() +'\''+
"sex='" + getSex() + '\''+
'}';
}
}
public class Customer extends Person {
private String customerId;
private String phone;
public static Customer builder() {
return new Customer();
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
//构建器 用来构建一个对象
public Customer() {
}
public Customer setCustomerId(String customerId){
this.customerId = customerId;
return this;
}
public String getCustomerId(){
return customerId;
}
public Customer Pwd(String pwd){
super.setPwd(pwd);
//this.pwd=pwd
return this;
}
}
public class Customer extends Person {
private String customerId;
private String phone;
~
public class Customer 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;
}
public String getCourierId() {
return courierId;
}
public void setCourierId(String courierId) {
this.courierId = courierId;
}
@Override
public String toString() {
return "Courier{" +
"courierId='" + courierId + '\''
+"name'" + getName() + '\''
+"age='" + getAge() + '\''
+"pwd='" + getPwd() + '\'' +
"sex='" + getSex() + '\'' +
'}';
}
}
~
import com.feige.beans.Customer;
import org.omg.CORBA.UserException;
import java.util.Scanner;
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).Pwd(pwd);
customer.setName(name);
customer.setAge(age);
customer.setPhone(phone);
customer.setSex(sex);
// 把上面的对象保存到数组
// CustomerData.save(customer);
}
}
package com.feige;
import java.util.Scanner;
public class Main {
Scanner sc = 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 = sc.nextInt();
switch (funNO){
case 1:
//用户注册
break;
case 2:
//登录系统
break;
case 3:
//商品查看
break;
case 4:
//退出系统
default:
sc.close();//关闭扫描器资源
System.exit(0); // 0 正常退出 非0 非正常的中断退出
}
}
public Scanner getSc() {
return sc;
}
public void setSc(Scanner sc) {
this.sc = sc;
}
public static void main(String[]args){
new Main().menu();
}
}