⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 operate.java

📁 无界面电话查询系统 operate 是操作类 专门是数据维护的 server是服务器 client是客户端 person是个人信息类 logo产生登陆图片 先operate在文件里面按提
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  		
  		while(true)
  		{   
  			System.out.println("请选择你要删除信息的类型 1:按姓名 2:按电话 3:退出");
            System.out.print("您的输入: ");
            int tempInt=Integer.parseInt(input.readLine());
            if(vc.size()<=0)
            {
            	System.out.print("!!!当前库中没有可用信息 此功能暂时不可用..");
            	break;
            }
           
         if(tempInt==1)
           {       
                 
                 System.out.println("请输入您要删除的姓名: ");
                 System.out.print("姓名是:");
                 String tempStr=input.readLine();
        	    for(int i=0;i<vc.size();i++)
        	     {
        		    Person ps=(Person)vc.get(i);
        		    if(ps.name.equals(tempStr))
        		      {
        			    vc.remove(i);
        			    isExist=true;
        			    System.out.println("删除成功 请继续..");
        		      }
        	     }
        	if(!isExist)
        	{
        		System.out.println("对不起 您要查找的信息不存在 请继续..");
        	}
         }
         if(tempInt==2)
           {       
                
                 System.out.println("请输入您要删除的电话: ");
                 System.out.print("号码是:");
                 String tempStr=input.readLine();
        	    for(int i=0;i<vc.size();i++)
        	     {
        		    Person ps=(Person)vc.get(i);
        		    if(ps.number.equals(tempStr))
        		      {
        			    vc.remove(i);
        			    isExist=true;
        			    System.out.println("删除成功 请继续..");
        		      }
        	     }
        	if(!isExist)
        	{
        	 	System.out.println("对不起 您要查找的信息不存在 请继续..");
        	}
         }
         if(tempInt==3)
         {
         	System.out.println("感谢您使用本系统,请继续..");
         	break;
           // 
         }
         
  	  }
        
  		
  		objectOut= new  ObjectOutputStream(
  		    	            new BufferedOutputStream(
  		    	            	new FileOutputStream(filepath)));
  		objectOut.reset();
  		objectOut.writeObject(vc);
  		objectOut.flush();
  		objectOut.close();
  		
		}catch(Exception e){System.out.println(e.getMessage());}
		 
	
		return isExist;
	}
	
	public  void  update(String path)
	{
		input=new BufferedReader(new InputStreamReader(System.in));
		filepath=path;
		Vector vector=null;
	    	
		ObjectOutputStream objectOut;
	    ObjectInputStream  objectIn;
	    
  		  
		
		try
		{
			objectIn=  new  ObjectInputStream(
  		    	            new BufferedInputStream(
  		    	            	new FileInputStream(filepath)));
  		    vector=(Vector)objectIn.readObject();
  		    objectIn.close();
		}catch(Exception f){System.out.println(f.getMessage());}            	
  		for(int i=0;i<vector.size();i++)
  		{
  		  	//System.out.println(vector.get(i));
  			
  		}
  	
  			
  		try{  
  			     while(true)
  		       {
  				  System.out.println("请输入您要修改的类型 1:按姓名修改 2:按电话修改:3 : 退出信息修改:");
  			      String tempInt=input.readLine();
  			      String tempStr="";
  			      boolean find=false;
  			if(tempInt.equals("1"))
  			{ 
  				System.out.println("请输入您要查找的姓名: ");
  				tempStr=input.readLine();
  				for(int i=0;i<vector.size();i++)
  			     {
  				    Person person=(Person)vector.get(i);
  				    if(tempStr.equals(person.name))
  				    {
  				    	System.out.println(person);
  				    	System.out.println("请输入您要更新的信息:");
  				    	System.out.print("姓名是:");
  				    	String tempname=input.readLine();
  				    	System.out.print("地址是:");
  				    	String tempaddress=input.readLine();
  				    	System.out.print("电话是:");
  				    	String tempnumber=input.readLine();
  				        person = new Person(tempname,tempaddress,tempnumber);
  				        vector.setElementAt(person,i); 
  				        find=true;
  				        System.out.println("更新成功 请继续");
  				    }
  			     }
  			     if(!find)
  			     {
  			     	System.out.println("对不起没有找到您要的信息! 请继续");
  			     }
  			}
  			
  			if(tempInt.equals("2"))
  			{
  				System.out.println("请输入您要查找的电话: ");
  				tempStr=input.readLine();
  				for(int i=0;i<vector.size();i++)
  			     {
  				    Person person=(Person)vector.get(i);
  				    if(tempStr.equals(person.name))
  				    {
  				    	System.out.println(person);
  				    	System.out.println("请输入您要更新的信息:");
  				    	System.out.print("姓名是:");
  				    	String tempname=input.readLine();
  				    	System.out.print("地址是:");
  				    	String tempaddress=input.readLine();
  				    	System.out.print("电话是:");
  				    	String tempnumber=input.readLine();
  				        person = new Person(tempname,tempaddress,tempnumber);
  				        vector.setElementAt(person,i); 
  				        find=true;
  				        System.out.println("更新成功 请继续");
  				    }
  			     }
  			     if(!find)
  			     {
  			     	System.out.println("对不起没有找到您要的信息! 请继续");
  			     }
  			}
  			if(tempInt.equals("3"))
  			{   
  			    
  				System.out.println("多谢使用修改功能 欢迎继续使用本系统");
  			
  				break;
  				
  			 }
  	 try
  	 {
  	 	objectOut= new  ObjectOutputStream(
  		    	                   new BufferedOutputStream(
  		    	            	       new FileOutputStream(filepath)));
  	             	objectOut.reset();
  		            objectOut.writeObject(vector);
  		            objectOut.flush();
  	                objectOut.close();
  	 }catch(Exception f){System.out.println(f.getMessage());}
  	 
  			
  			
  		  }
        
 }catch(Exception e){System.out.println(e.getMessage());}
        
        	
     }

      
	public static void main(String[] arg){
		Operate operate=new Operate();
        String code=" ",name=" ";
        int count=0;
    BufferedReader   in=new BufferedReader(new InputStreamReader(System.in));
       String s="";
       while(true)
       {
       	  
       	  try{  
       	  
       	  System.out.println("                  ◎请输入管理员姓名和密码◎");
       	  System.out.println("〓警告:您只有三次机会 三次后系统会自动退出〓 ");
          System.out.print("★姓名:   ");
          name=in.readLine();
          System.out.print("★密码:   ");
          code=in.readLine();
          if(code.equals("123456")&&name.equals("wtyl0088"))
          {
          	System.out.println("欢迎来到服务器管理系统");
          	break;
          	
          }
          else 
          {
          	System.out.println("对不起 你的输入有错误 请重试 ");
          	count++;
            if(count>3)
           {
          	System.exit(0);
           }
          	
          }
          
          }catch(Exception e){}
      }
       
       while(true)
       { 
         try
         {
         	System.out.println("请输入服务类型 1:插入 2: 删除 3: 修改 4: 查询 5 :退出");
       	     s=in.readLine();
         }catch(Exception e){
         }
       	 
       	 if(s.equals("1"))
       	 {
       	 	 operate.insert("d:\\information.txt");
       	 }
       	 if(s.equals("2"))
       	 {
       	 	 operate.delete("d:\\information.txt");
       	 }
       	 if(s.equals("3"))
       	 {
       	 	 operate.update("d:\\information.txt");
       	 }
       	 if(s.equals("4"))
       	 {
       	 	 operate.search("d:\\information.txt");
       	 }
       	 if(s.equals("5"))
       	 {
       	 	 System.out.println("●感谢您的使用 如有任何问题 请发送电子邮件wtyl00882126.com联系作者●");
       	 	 break;
       	 }
       }
       
	}
	
		 

	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -