您好,登錄后才能下訂單哦!
Java
b) 行為:
i. 學習:
3) 本地公安局類:
a) 屬性:公安局人員備案庫(最大存儲200個)
b) 移民:(傳入當前用戶的對象)
先判斷當前公安局人員備案庫里是否存在當前用戶
a) 沒有的話則打印您是未成年人還不能移民,
b) 若有則判斷當前的人員的信譽程序是否有無犯罪歷史
i. 有的話則不能移民,
ii. 若沒有犯罪歷史,
再判斷文化程度是否達到大學文化
a) 沒有則需要再等待1年審核時間
b) 若達到大學文化,則可以移民,并將本地公安局和國家人員管理庫的當前人員永久刪除。
4) 國家人員管理庫:
a) 屬性:全國國家安全總局人員備案庫(最大存儲3000000)
b) 行為:
i. 查詢人員:
邏輯:傳入人員對象
a) 則先看是否存在,若存在則刪除,不存在則打印:人員身份未備案
答案:
1.系統目錄展示:
2.Address類:
package cn.letter.address;
public class Address {
private String country;
private String province;
private String street;
private String houseNumber;
public Address() {
}
public Address(String country, String province, String street,
String houseNumber) {
this.country = country;
this.province = province;
this.street = street;
this.houseNumber = houseNumber;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getHouseNumber() {
return houseNumber;
}
public void setHouseNumber(String houseNumber) {
this.houseNumber = houseNumber;
}
}
3.TextBook類:
package cn.letter.study;
public class Textbook {
private String[] course={"小學課本","初中課本","高中課本","大學課本","研究生課本","博士生課本","教授課本"};
public String[] getCourse() {
return course;
}
public void setCourse(String[] course) {
this.course = course;
}
}
4.Person類:
package cn.letter.User;
import java.text.SimpleDateFormat;
import java.util.Date;
import cn.letter.address.Address;
import cn.lttest.uitl.ScannerHelp;
import cn.lttest.uitl.UUIDutil;
public class Person {
private String ID;
private String name;
private char sex;
private int age;
private String password;
private Boolean state;
private Address address;
private Date date;
private Date applyDate;
private int reputation;
private int culture;
private int study;
private String[] repu = { "無犯罪歷史", "有過輕度犯罪歷史", "嚴重犯罪歷史", "殺人罪但是有期徒刑",
"殺人罪并執行死刑", "個人榮譽小貼士", "國家級別榮譽獎章 " };
private String[] cul = { "沒有教育歷史", "小學文化", "初中文化", "高中文化", "大學文化(碩士生)",
"研究生", "博士生", "教授" };
public String getID() {
return ID;
}
public void setID(String iD) {
ID = iD;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public Boolean getState() {
return state;
}
public String getDate() {
return new SimpleDateFormat("yyyy-MM-dd").format(date);
}
public void setApplyDate(Date applyDate) {
this.applyDate = applyDate;
}
public String getApplyDate() {
return applyDate == null ? "" : new SimpleDateFormat("yyyy-MM-dd")
.format(applyDate);
}
public int getReputation() {
return reputation;
}
public int getCulture() {
return culture;
}
public int getStudy() {
return study;
}
public String[] getCul() {
return cul;
}
public String[] getRepu() {
return repu;
}
public Person(String name, char sex, int age, String password,
Address address) {
super();
ID = UUIDutil.UUID();
this.name = name;
this.sex = sex;
this.age = age;
this.password = password;
this.state = true;
this.address = address;
this.date = new Date();
this.reputation = 0;
this.culture = 0;
this.study = 0;
}
public Person() {
}
public void stud() {
int stu = ScannerHelp.getInt("課本");
if (stu < culture) {
study++;
} else if (stu == culture) {
study++;
culture++;
} else
System.out.println("學歷級別未達到!");
if (culture > 3) {
if (culture == 7)
reputation = 6;
else
reputation = 5;
}
System.out.println("當前學歷:" + getCul()[getCulture()]);
}
}
5.學生類:
package cn.letter.User;
import cn.letter.address.Address;
public class Student extends Person {
public Student() {
}
public Student(String name, char sex, int age, String password,
Address address) {
super(name, sex, age, password, address);
}
@Override
public String toString() {
return "人員身份號:" + getID() + "\n姓名:" + getName() + "\n性別:" + getSex()
+ "\n年齡:" + getAge() + "\n密碼:" + getPassword() + "\n國家:"
+ getAddress().getCountry() + "\n地區:"
+ getAddress().getProvince() + "\n街道:"
+ getAddress().getStreet() + "\n門牌號:"
+ getAddress().getHouseNumber() + "\n注冊日期:" + getDate()
+ "\n信譽程度:" + getRepu()[getReputation()] + "\n文化程度:"
+ getCul()[getCulture()] + "\n學習次數:" + getStudy();
}
}
6.本地公安局類:
package cn.lttest.country;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import cn.letter.User.Student;
public class AddressPerson {
static Student[] stu = new Student[200];
static Country coun = new Country();
static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
public static Student[] getStu() {
return stu;
}
public static void setStu(Student[] stu) {
AddressPerson.stu = stu;
}
public static void move(String name) {
boolean chose = false;
int ch = 0;
long time = 0;
String eq = "";
System.out.println(stu[0].getApplyDate());
for (int i = 0; i < stu.length; i++) {
if (stu[i].getName() != null && stu[i].getName().equals(name)) {
ch = i;
if (stu[i].getReputation() == 0 || stu[i].getReputation() == 5
|| stu[i].getReputation() == 6) {
if (stu[i].getCulture() < 4) {
if (stu[i].getApplyDate().equals(eq)) {
stu[i].setApplyDate(new Date());
System.out.println("需要審核時間一年");
break;
} else {
try {
time = (sdf.parse(stu[i].getApplyDate())
.getTime() - sdf
.parse(stu[i].getDate()).getTime())
/ 1000 / 60 / 60 / 24;
break;
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (time < 365) {
System.out.println("需要審核時間" + time + "天");
break;
} else {
chose = true;
break;
}
} else {
chose = true;
break;
}
} else {
System.out.println("有犯罪歷史,無法移民");
break;
}
} else {
System.out.println("您是未成年人,不能移民");
break;
}
}
if (chose == true) {
stu[ch] = null;
for (int j = 0; j < stu.length; j++) {
if (coun.stu[j].getName() != null && coun.stu[j].getName().equals(name)) {
System.out.println("移民成功!");
coun.stu[j] = null;
break;
}
}
}
}
public static boolean isExists(String name){
if (name == null) {
return true;
}
for (int i = 0; i < stu.length; i++) {
if (stu[i].getName().equals(name)) {
return false;
}
}
return true;
}
}
7.國家人員庫類:
package cn.lttest.country;
import cn.letter.User.Person;
import cn.letter.User.Student;
import cn.letter.address.Address;
import cn.letter.study.Textbook;
import cn.lttest.uitl.ScannerHelp;
public class Country {
static Person[] stu = new Person[3000000];
static AddressPerson addr = new AddressPerson();
static Textbook tk = new Textbook();
public static Person[] getStu() {
return stu;
}
public static void setStu(Student[] stu) {
Country.stu = stu;
}
public void addUser(Student use) {
for (int i = 0; i < stu.length; i++) {
if (stu[i] != null && stu[i] == use) {
System.out.println("已存在");
break;
} else if (stu[i] == null) {
stu[i] = use;
System.out.println("人員入庫成功!");
break;
}
}
for (int i = 0; i < addr.stu.length; i++) {
if (addr.stu[i] != null && addr.stu[i] == use) {
break;
} else if (addr.stu[i] == null) {
addr.stu[i] = use;
break;
}
}
}
public void delUser(String name) {
boolean chose = false;
for (int i = 0; i < stu.length; i++) {
if (stu[i] != null && stu[i].getName().equals(name)) {
stu[i] = null;
chose = true;
break;
}
}
System.out.println(chose == true ? "已刪除" : "人員身份未備案");
}
public void showUser(String name) {
int j = 0;
boolean chose = false;
for (int i = 0; i < stu.length; i++) {
if (stu[i] != null && stu[i].getName().equals(name)) {
j = i;
chose = true;
break;
}
}
System.out.println(chose == true ? "人員身份號:" + stu[j].getID() + "\n姓名:"
+ stu[j].getName() + "\n性別:" + stu[j].getSex() + "\n年齡:"
+ stu[j].getAge() + "\n密碼" + stu[j].getPassword() + "\n居住地址"
+ stu[j].getAddress() + "\n注冊日期" + stu[j].getDate() + "\n信譽程度"
+ stu[j].getRepu()[stu[j].getReputation()] + "\n文化程度"
+ stu[j].getCul()[stu[j].getCulture()] + "\n學習次數"
+ stu[j].getStudy() : "人員身份為備案");
}
public Student add() {
String name = ScannerHelp.getString("姓名");
char sex = ' ';
while (true) {
System.out.println("1:男\t2:女");
int sexx = ScannerHelp.getInt("性別");
if (sexx == 1) {
sex = '男';
break;
} else if (sexx == 2) {
sex = '女';
break;
} else
System.out.println("輸入錯誤,請重新輸入!");
}
int age = ScannerHelp.getInt("年齡");
String password = "";
while (true) {
System.out.println("密碼為6-12位");
password = ScannerHelp.getString("密碼");
if (password.length() > 12 || password.length() < 6)
System.out.println("輸入錯誤,請重新輸入!");
else
break;
}
String country = ScannerHelp.getString("國家");
String province = ScannerHelp.getString("地區");
String street = ScannerHelp.getString("街道");
String door = ScannerHelp.getString("門牌號");
Address addr = new Address(country, province, street, door);
Student stu = new Student(name, sex, age, password, addr);
return stu;
}
public void study(String name) {
for (int i = 0; i < stu.length; i++) {
if (stu[i] != null && stu[i].getName().equals(name)) {
stu[i].stud();
break;
}
}
}
}
8.輸入幫助類:
package cn.lttest.uitl;
import java.util.Scanner;
public class ScannerHelp {
static Scanner sc = new Scanner(System.in);
/**
* 幫助我們輸入整型數據
*
* @param name
* @return
*/
public static int getInt(String name) {
System.out.print("請輸入" + name + ":");
int num = sc.nextInt();
sc.nextLine();
return num;
}
/**
* 幫助我們輸入字符串
*
* @param name
* @return
*/
public static String getString(String name) {
System.out.print("請輸入" + name + ":");
String num = sc.nextLine();
return num;
}
}
9.隨機獲取類:
package cn.lttest.uitl;
import java.util.Random;
public class UUIDutil {
static Random random = new Random();
public static String UUID() {
String ID = "";
char[] id = new char[62];
for (int i = 0; i < 10; i++) {
id[i] = (char) (48 + i);
}
for (int i = 10, j = 10; i < 62; i++, j++) {
id[i] = (char) (55 + j);
id[i + 1] = (char) (55 + 32 + j);
i++;
}
for (int i = 0; i < 32; i++) {
ID += id[random.nextInt(62)];
}
return ID;
}
}
10.視圖類全局程序入口:
package cn.letter.View;
import java.util.Scanner;
import cn.letter.User.Student;
import cn.lttest.country.AddressPerson;
import cn.lttest.country.Country;
import cn.lttest.uitl.ScannerHelp;
public class View {
static Student stud = new Student();
static Country coun = new Country();
static AddressPerson add = new AddressPerson();
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
while (true) {
System.out.println("*****************************");
System.out.println("\t 公安局\n\t 人員注冊系統\n\t V1.0");
System.out.println("*****************************");
System.out.print("\t1.人員入庫");
System.out.println("\t2.人員刪除");
System.out.print("\t3.移民");
System.out.println("\t4.學習");
System.out.print("\t5.查詢");
System.out.println("\t6.退出\n請輸入您的選擇:");
int ch = sc.nextInt();
switch (ch) {
case 1:
coun.addUser(coun.add());
break;
case 2:
coun.delUser(ScannerHelp.getString("姓名"));
break;
case 3:
add.move(ScannerHelp.getString("姓名"));
break;
case 4:
coun.study(ScannerHelp.getString("姓名"));
break;
case 5:
coun.showUser(ScannerHelp.getString("姓名"));
break;
case 6:
System.out.println("bye!");
break;
default:
System.out.println("輸入有誤,請重新輸入!");
/*
* for (int i = 0; i < coun.getStu().length; i++) { if
* (coun.getStu()[i] != null)
* System.out.println(coun.getStu()[i].toString()); else
* System.out.print(""); }
*/
break;
}
//
for (int i = 0; i < coun.getStu().length; i++) {
if (coun.getStu()[i] != null
&& coun.getStu()[i].getReputation() == 4) {
coun.delUser(coun.getStu()[i].getName());
} else
System.out.print("");
}
if (ch == 6) {
break;
}
}
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。