第二周总结

这周先学习了String StringBuffered类 字符串处理
包含的方法很多用到的就String类的String[] split(regex) 字符串按Regex拆分
StringBuffered的append()追加方法. 
String到很多地方都要用到里面的一些方法自己都认真看了的.
到后来分成项目组做个迷你通讯录
做这个项目安全按照需求-->分析-->设计-->编码-->测试优化来的.
做了这个项目感觉自己分析的时侯还不是很强.虽然一些实现自己知道.但没有详细地分析出来写给小组成员讨论.还有就是帮助了这个小组的一些成员.嘿嘿 大家互相帮助嘛!
通过这个项目知道了一个项目开发的流程,感觉到了团队协作的重要性.还有不是老师提及没写详细注释的习惯.


后面帖一下我们小组的代码: 

/*********************************************
 * 项目名:迷你通讯录                         *
 * 类 名:MiniBook                           *
 * 作 者:                           *
 * 版 本:1.0.0.1                            *
 * 日 期 2006-08-11                         *
 *********************************************/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.util.Properties;
 
 
public class MiniBook
{
       public static void main(String [] args)
       {
              MiniBook mb = new MiniBook(); //实例化对象
             
              System.out.println();
              System.out.println();
              System.out.println();
              System.out.println("/t/t*****************************************");
              System.out.println("/t/t*                                        *");
              System.out.println("/t/t*                                       *");
              System.out.println("/t/t*           欢迎使用MINI通讯录           *");
              System.out.println("/t/t*                                       *");
              System.out.println("/t/t*                                       *");
              System.out.println("/t/t* 制作人:datuo         版本:1.0.0.1    *");
              System.out.println("/t/t* 时 间:2006-8-11                      *");
              System.out.println("/t/t*                                       *");
              System.out.println("/t/t*                                       *");
              System.out.println("/t/t*****************************************");
              System.out.println();
              System.out.println();
              System.out.println();
             
              mb.login()      ;             //调用登陆函数
       }
      
                                          /************
                                           *   登陆    *
                                           ************/
       public void login()
       {
              int userCount     = 0; //用户名错误计数器
              int passCount = 0; //密码错误计数器
              BufferedReader br   = new BufferedReader(new InputStreamReader(System.in));
              Properties proLogin = new Properties();
             
              System.out.println("=========用户登陆=======");
              do
              {
                     try
                     {
                            String name    = null,password = null; //输入的用户名和密码
                            Boolean isUser = false;   //判断是否登陆
                            System.out.print("请输入用户名:");
                            String strName = br.readLine();
                            proLogin.load(new FileInputStream(strName+".properties"));
                            if(strName.equals(proLogin.getProperty(strName+".name")))    
                            {
                                   isUser   = true;
                                   password = proLogin.getProperty(strName+".password");
                                  
                                   System.out.print("请输入密码:");
                                   String pwd = br.readLine();
                                   if(pwd.equals(password))
                                   {
                                          System.out.println("登陆成功!");
                                          this.mainWindows(); //调用显示主窗口函数
                                          break;
                                   }
                                   else
                                   {
                                          System.out.println("密码错误!");
                                          passCount++;
                                   }
                            }
      
                            if(!isUser)
                            {
                                   System.out.println("用户名错误");
                                   userCount++;
                            }
                     }
                     catch(FileNotFoundException e1)
                     {
                            System.out.println("属性文件没有找到!");
                            passCount++;
                     }
                     catch(Exception e)
                     {                         
                     }
 
              }while(userCount < 3 && passCount < 3); 
       }
 
      
                                          /************
                                           *   主界面 *
                                           ************/
       public void mainWindows()
       {
              int choice = 0; //保存用户选择
              BufferedReader br   = new BufferedReader(new InputStreamReader(System.in));
              do
              {
                     System.out.println();
                     System.out.println();
                     System.out.println("/t/t========登陆界面========");
                     System.out.println("***************************************************");
                     System.out.println("/t/t欢迎使用MINI通讯录");
                     System.out.println("/t/t【1:添加用户】 ");
                     System.out.println("/t/t【2:用户查询】");
                     System.out.println("/t/t【3:信息更改】");
                     System.out.println("/t/t【4:退     出】");
                     System.out.println("---------------------------------------------------");
                     System.out.print("请输入(1-4)进行操作:");
                    
                     try
                     {
                            choice = Integer.parseInt(br.readLine());
                     }
                     catch(Exception e)
                     {
                            System.out.println("Error:请输入数字!!");
                     }
                    
                     switch(choice)
                     {
                            case (1):
                                   this.add(); //调用添加函数
                                   break;
                            case (2):
                                   this.query(); //调用查询函数
                                   break;
                            case (3):
                                   this.edit();//调用编辑函数
                                   break;
                            case (4):
                                   System.out.println("谢谢使用!!");
                                   System.exit(1); //退出
                                   break;
                            default:
                                   System.out.println("Error:请输入(1-4)选择!!");
                                   break;
                     }
              }while(true);
       }
      
 
                                          /************
                                           *   添加    *
                                           ************/
       public void add()
       {
              BufferedReader br   = new BufferedReader(new InputStreamReader(System.in));
              Properties     pro = new Properties();
              String newName = null;
              String newAge   = null;
              String newSex   = null;
              String newPhone = null;
              System.out.println("/t/t========添加模块========");
              System.out.println("***************************************************");
 
              try
              {
                      /*接收用户输入新的姓名,年龄,性别,电话*/
                     System.out.println("请输入添加的姓名:");
                     newName = br.readLine();
                     System.out.println("请输入添加的年龄:");
                     newAge   = br.readLine();
                     System.out.println("请输入添加的性别(male/female):");
                     newSex   = br.readLine();
                     System.out.println("请输入添加的电话号码:");
                     newPhone = br.readLine();                 
              }           
              catch(Exception e)
              {
                     e.printStackTrace();
              }
              /*设置键和值*/
              pro.setProperty(newName+".name", newName);
              pro.setProperty(newName+".age", newAge);
              pro.setProperty(newName+".sex", newSex);
              pro.setProperty(newName+".phone", newPhone);
             
              /*保存文件*/
              try
              {
                     pro.store(new FileOutputStream("telephone.properties",true),null);
              }
              catch(Exception e)
              {
                     e.printStackTrace();
              }
              System.out.println("添加成功!!");
       }
      
 
                                          /************
                                           *   查询    *
                                           ************/
       public String query() 
       {
              Properties    pro = new Properties();
              BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
              String queryName = null; //保存用户输入的查询姓名
              System.out.println("==============");
              try
              {
                     pro.load(new FileInputStream("telephone.properties"));
              }    
              catch(Exception e)
              {
                     System.out.println("文件没有找到!");
              }
             
              System.out.println("请输入的姓名:");
              try
              {
                     queryName = br.readLine();
              }
              catch(Exception e)
              {
                     e.printStackTrace();     
              }    
             
              if(queryName.equals(pro.getProperty(queryName+".name")))
              {
                     String age = pro.getProperty(queryName+".age");
                     String sex = pro.getProperty(queryName+".sex");
                     String phone = pro.getProperty(queryName+".phone");
                     System.out.println("姓名/t/t年龄/t姓别/t电话号码");
                     System.out.println("--------------------------------------------");   
                     System.out.println(queryName+"/t/t"+age+"/t"+sex+"/t"+phone);
                     System.out.println("--------------------------------------------");
                     return queryName;//返回字符串用户查询的姓名
              }
              else
              {
                     System.out.println("没有找到 '"+queryName+"' 的信息!");
                     return null;//没找到返回空
              }
 
             
       }
 
 
                                          /************
                                           *   修改    *
                                           ************/
       public void edit()
       {
              String editName = null; //修改的姓名
              int choice   = 0; //保存用户的选择
              BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
              editName = this.query(); //调用查询函数
              if(editName!=null) //找到了该姓名
              {
                     System.out.println();
                     System.out.println("=====================================");
                     System.out.println("/t【1:更新年龄】 ");
                     System.out.println("/t【2:更新电话】");
                     System.out.println("/t【3:更新性别】");
                     System.out.println("/t【4:退     出】");
                     System.out.println("--------------------------------------");
                     System.out.print("请输入(1-4)进行操作:");
                     try
                     {
                                   choice = Integer.parseInt(br.readLine());
                     }
                     catch(Exception e)
                     {
                            e.printStackTrace();
                     }
                     switch(choice)
                     {
                            case 1:
                                   this.upDate("age", editName); //传递参数 修改的项和修改的姓名
                                   break;
                            case 2:
                                   this.upDate("phone", editName);
                                   break;
                            case 3:
                                   this.upDate("sex", editName);
                                   break;
                            case 4:   
                                   break;
                            default:
                                   System.out.println("Error:请输入(1-4)选择!!");
                                   break;
                     }
              }
       }
 
       public void upDate(String option, String upDateName)
       {
              String input      = null; //保存用户的输入
              Properties pro    = new Properties();
              BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
              System.out.println("===================");
              System.out.print("Please input "+option+":");
              try
              {
                      input = br.readLine();
              }
              catch(Exception e)
              {
                     e.printStackTrace();
              }
              pro.setProperty(upDateName+"."+option, input);//修改
              try
              {
                     pro.store(new FileOutputStream("telephone.properties",true),null);
                     System.out.println("更新成功!!");
              }
              catch(Exception e)
              {
                     e.printStackTrace();
              }
             
       }
 
}
最后下周好像要学客户端编程了.记住也很认同尹老说的一句话:"只有想不到,没有做不到".
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值