to toonycheng
来源:互联网 发布:闺蜜网络语 编辑:程序博客网 时间:2024/04/30 08:45
User类:
Manager类:
Main:
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package wind.angel.app.entry;
- /**
- *
- * @author Hawkeyes
- */
- public class User implements Cloneable{
- private String id;
- private String name;
- private String password;
- public String getId() {
- return id;
- }
- public boolean isInit() {
- if(id.equals("") && name.equals("") && password.equals(""))
- return true;
- return false;
- }
- public void setId(String id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public User() {
- this.id = "";
- this.name = "";
- this.password = "";
- }
- public User(String id, String name, String password) {
- this.id = id;
- this.name = name;
- this.password = password;
- }
- @Override
- public String toString() {
- return "id: " + id + " name: " + name + " password: " + password + ".";
- }
- @Override
- protected Object clone() throws CloneNotSupportedException {
- return super.clone();
- }
- }
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package wind.angel.app.util;
- import java.util.ArrayList;
- import wind.angel.app.entry.User;
- /**
- *
- * @author Hawkeyes
- */
- public class Manager {
- private ArrayList<User> userlist;
- private User user = new User();
- public Manager() {
- userlist = new ArrayList<User>();
- }
- public Manager(ArrayList<User> userlist) {
- this.userlist = userlist;
- }
- public void initUser(User u){
- u=null;
- }
- public void list() {
- for(User u:userlist){
- System.out.println(u);
- }
- }
- public User searchById(String id){
- initUser(user);
- for(User u:userlist){
- if(u.getId().equals(id)){
- user=u;
- break;
- }
- }
- return user;
- }
- public User searchByName(String name){
- initUser(user);
- for(User u:userlist){
- if(u.getName().equals(name)){
- user=u;
- break;
- }
- }
- return user;
- }
- public boolean add(User u){
- return userlist.add(u);
- }
- public boolean remove(User u){
- return userlist.remove(u);
- }
- }
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package wind.angel.app;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import wind.angel.app.entry.User;
- import wind.angel.app.util.Manager;
- /**
- *
- * @author Hawkeyes
- */
- public class Main {
- static private boolean flag = true;
- static String str;
- static InputStreamReader isr = new InputStreamReader(System.in);
- static BufferedReader br = new BufferedReader(isr);
- static private User user = new User();
- static private Manager manager = new Manager();
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws IOException {
- // TODO code application logic here
- while (flag) {
- System.out.println("------------------------------------------------");
- System.out.println("Please select the function:");
- System.out.println("1. Add user");
- System.out.println("2. Search user");
- System.out.println("3. Delete user");
- System.out.println("4. List user");
- System.out.println("exit. exit app");
- System.out.println("press the number of function: ");
- str = br.readLine();
- //System.out.println(str);
- if (str.equals("exit")) {
- break;
- } else if (str.equals("1")) {
- addUser();
- } else if (str.equals("2")) {
- searchUser();
- } else if (str.equals("3")) {
- deleteUser();
- } else if (str.equals("4")) {
- listUser();
- } else {
- System.out.println("The function code is invalid.");
- }
- continue;
- }
- }
- private static void addUser() {
- String[] strarr;
- System.out.println("press user information by '<id> <name> <password>'.");
- try {
- str = br.readLine();
- } catch (IOException ex) {
- Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
- }
- strarr = str.split(" ");
- //user.setId(strarr[0]);
- //user.setName(strarr[1]);
- //user.setPassword(strarr[2]);
- if (manager.add(new User(strarr[0],strarr[1],strarr[2]))) {
- System.out.println("Add success.");
- } else {
- System.out.println("Add fail.");
- }
- }
- private static void deleteUser() {
- String[] sa;
- System.out.println("usage: <id|name> <value>.");
- try {
- str = br.readLine();
- } catch (IOException ex) {
- Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
- }
- sa = str.split(" ");
- if (sa[0].equals("id")) {
- user = manager.searchById(sa[1]);
- } else if (sa[0].equals("name")) {
- user = manager.searchByName(sa[1]);
- }
- if(user.isInit()){
- System.out.println("The user is not found.");
- return;
- }
- if(manager.remove(user))
- System.out.println("the user " + user.getName() + " has deleted.");
- else
- System.out.println("can't delete the user " + user.getName() + ".");
- }
- private static void listUser() {
- manager.list();
- }
- private static void searchUser() {
- String[] sa;
- System.out.println("usage: <id|name> <value>.");
- try {
- str = br.readLine();
- } catch (IOException ex) {
- Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
- }
- sa = str.split(" ");
- if (sa[0].equals("id")) {
- user = manager.searchById(sa[1]);
- } else if (sa[0].equals("name")) {
- user = manager.searchByName(sa[1]);
- }
- if(user.isInit()){
- System.out.println("The user is not found.");
- return;
- }
- System.out.println(user);
- }
- }
- to toonycheng
- to
- 【english】to to it
- To learn, to share.
- To Read
- To Learn
- listen to
- thanks to ......
- to TTT
- TO DO ... ...
- TO ROUTLE
- To Sophia
- to:SingYes
- to:雷艾伦
- TO Z28
- to bashman
- TO 红梅
- TO EveryOne
- linux下都集成Oracle了!!!
- java 多线程 购票
- [转载] ORA-12535: TNS:operation timed out
- 以9i为例,oracle服务器端的主要服务介绍
- Oracle客户端穿过防火墙连接服务器
- to toonycheng
- 让Linux操作系统开机默认进入文本模式
- 关于交换机 VLAN ,VPN ,端口镜像
- [翻译]Wintermute联机文档之二
- Eclipse快捷键大全(转载)
- 搜狗拼音输入法漂亮皮肤 LeftSide 推荐下载
- Asp.net(C#)实现验证码功能
- 一切从零开始------软件篇
- 人脸识别系统第一版完成