課堂代碼
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;
}
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;
}
//構(gòu)建器 用來構(gòu)建一個對象
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 只能出現(xiàn)在第一行
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);
// 把上面的對象保存到數(shù)組
// 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ǒ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 = sc.nextInt();
switch (funNO){
case 1:
//用戶注冊
break;
case 2:
//登錄系統(tǒng)
break;
case 3:
//商品查看
break;
case 4:
//退出系統(tǒng)
default:
sc.close();//關(guān)閉掃描器資源
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();
}
}