Home  >  Article  >  Java  >  Java implementation of address book management system tutorial

Java implementation of address book management system tutorial

Guanhui
Guanhuiforward
2020-07-24 17:37:414405browse

Java implementation of address book management system tutorial

The example in this article shares the specific code for implementing the address book management system in Java for your reference. The specific content is as follows

Process of completing the project:

1. Determine the general direction according to the needs
2. Function module analysis
3. Interface implementation
4. Function module design
5.coding
6. Code test

The following is the source code:

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.concurrent.SynchronousQueue;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import javax.swing.text.html.HTMLDocument.Iterator;


class Infro{
 public String id;
 public String name;
 public String sex;
 public String address;
 public String e_mail;
 public String phoneNumber;
 static int index = 0;
 static ArrayList list = new ArrayList();
 static int len = list.size();
 //构造函数
 public Infro(String id,String name,String sex,String address,String e_mail,String phoneNumber){
 this.id = id;
 this.name = name;
 this.sex = sex;
 this.address = address;
 this.e_mail = e_mail;
 this.phoneNumber = phoneNumber;
 }
 public String toString(){
 return "编号:"+id+" 姓名:"+name+" 性别:"+sex+" 通讯地址:"+address+" 邮箱地址:"+e_mail+" 电话:"+phoneNumber;
 }

 /**
 * 添加功能
 **/
 public static void addFunction(){//添加功能
 Infro infro = new Infro("","","","","","");
 System.out.println("请输入添加的数据:");
 Scanner in = new Scanner(System.in);
 System.out.println("输入编号:");
 infro.id = in.next();
 System.out.println("输入姓名:");
 infro.name = in.next();
 System.out.println("输入性别:");
 infro.sex = in.next();
 System.out.println("输入通讯地址:");
 infro.address = in.next();
 System.
 out.println("输入邮箱地址:");
 infro.e_mail = in.next();
 System.out.println("输入电话:");
 infro.phoneNumber = in.next();
 list.add(index,infro);
 index++;
 if(list.isEmpty()){
 System.out.println("数据添加失败啦");
 }else{
 System.out.println("数据添加成功啦");
 len++;//list集合长度加一
// System.out.println(list.get(0).toString());
 }

 }
// public static void deleteFunction(){//删除功能
// System.out.println("输入要删除的联系人的编号");
// Scanner in_2 = new Scanner(System.in);
// String d1 = in_2.nextLine();
// for(int a= 0; a it = list.iterator();
 while (it.hasNext()){
 Infro infro = it.next();
 if (infro.id.equals(d1)){
 it.remove();
 --index;//一定要加这个,否则当做了删除操作再做添加操作的时候会出现异常(类似于指针,栈)
 System.out.println("删除完毕"+"此时通讯录记录条数为:" + --len);
 }
 }
 }
 /**
 * 修改功能
 **/
 public static void reditFunction(){
 System.out.println("输入要修改的通讯录的Id");
 Scanner in_r = new Scanner(System.in);
 String r1 = in_r.nextLine();
 for(int a = 0; a < len;a++){
 if(r1.equals(list.get(a).id)){
 System.out.println("输入修改后的姓名:");
 String name_1 = in_r.next();
 list.get(a).name = name_1;
 System.out.println("输入修改后的性别:");
 String sex_1 = in_r.next();
 list.get(a).sex = sex_1;
 System.out.println("输入修改后的通讯地址:");
 String address_1 = in_r.next();
 list.get(a).address = address_1;
 System.out.println("输入修改后的邮箱地址:");
 String e_mail_1 = in_r.next();
 list.get(a).e_mail = e_mail_1;
 System.out.println("输入修改后的电话:");
 String phoneNumber_1 = in_r.next();
 list.get(a).phoneNumber = phoneNumber_1;
 System.out.println("数据修改完毕");
 }
 }
 }
 /**
 * 查询功能
 **/
 public static void searchFunction() throws Exception{//查询功能
 System.out.println("请输入要查询的姓名:");
 Scanner in_1 = new Scanner(System.in);
 String s1=in_1.nextLine();
 for(int a= 0; a

Recommended tutorial: "Java Tutorial"

The above is the detailed content of Java implementation of address book management system tutorial. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete