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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。